S
Sharon
hi,
I want to compare character, if the string contains character "-" then it
will print Hello on the screen
however, neither method (1) nor method (2) work in the code below:
so what the correct code should be? thanks!
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
char *str;
*str = "abc - xyz";
for (i=0; i<35; i++){
/* method (1) does not work ! */
if (strcmp(str, "-") == 0) printf("Hello1");
/* method (2) shows nth ! */
if (str == "-") printf("Hello2");
}
system("PAUSE");
return 0;
}
I want to compare character, if the string contains character "-" then it
will print Hello on the screen
however, neither method (1) nor method (2) work in the code below:
so what the correct code should be? thanks!
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
char *str;
*str = "abc - xyz";
for (i=0; i<35; i++){
/* method (1) does not work ! */
if (strcmp(str, "-") == 0) printf("Hello1");
/* method (2) shows nth ! */
if (str == "-") printf("Hello2");
}
system("PAUSE");
return 0;
}