Click here to Skip to main content
15,889,403 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:

 

For some reason when I try to compile this program strange things are happening like the file name is changed to "string.h". Any ideas?

C++
#include <stdio.h>
#include <string.h>

int main()

{
    char str1[20] = "Hello\0" ;
    char str2[20] = "everyone\0" ;
    printf("%i\n",strlen(str1)) ;
    printf("%i\n",strcmp(str2)) ;
    return 0;
}
Posted
Updated 26-Nov-09 10:06am
v2

The standard strcmp() function takes two arguments, since it compares two strings. I'm surprised your compiler will even compile that line with "strcmp(str2)" in it -- it really shouldn't.

By the way, you don't have to add "\0" to the ends of the strings you define. The compiler will do that for you.

 
Share this answer
 

I thought strcmp was supposed to compare 2 strings.

And which file is changing to string.h? The file that the above code is in?

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900