开发者

why comparing 2 equal strings(printing on screen) with strcmp function give wrong answer?

开发者 https://www.devze.com 2023-02-24 17:08 出处:网络
I tried to compare 2 IP Addresses stored in 2 character arrays. I get the first IP Add char array from socket and the seco开发者_JS百科nd IP Add char array from text file. When I use strcmp function,

I tried to compare 2 IP Addresses stored in 2 character arrays. I get the first IP Add char array from socket and the seco开发者_JS百科nd IP Add char array from text file. When I use strcmp function, I got a non-zero value(which means 2 strings are not equal) although when I tried to printf on the screen , they are equal. Any idea about my prob?


Probably the problem is a special character like '\n', '\r', ... in your char array (from text file). Try to delete them ;-)

How to remove a carriage return from a string in C?

0

精彩评论

暂无评论...
验证码 换一张
取 消