user647868
user647868

Reputation: 13

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

I tried to compare 2 IP Addresses stored in 2 character arrays. I get the first IP Add char array from socket and the second 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?

Upvotes: 0

Views: 590

Answers (1)

Sandro Munda
Sandro Munda

Reputation: 41080

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?

Upvotes: 3

Related Questions