|
-
March 7th, 2004, 08:51 AM
#1
array character to character
Code:
#include <stdio.h>
#include <string.h>
main()
{
const char *temp="hello";
const char *string="how";
printf("%d",strcmp(temp[0],string[0]));
}
The code gave me the following warning msg.
c:\documents and settings\winson\desktop\data structure\forum.c(10) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'const char '
c:\documents and settings\winson\desktop\data structure\forum.c(10) : warning C4024: 'strcmp' : different types for formal and actual parameter 1
c:\documents and settings\winson\desktop\data structure\forum.c(10) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'const char '
c:\documents and settings\winson\desktop\data structure\forum.c(10) : warning C4024: 'strcmp' : different types for formal and actual parameter 2
I would like to compare some of the character between two strings.
I would like to know how i can solved this problem. For your information, i would like the solution in C and not C++. Thanks
Last edited by winsonlee; March 7th, 2004 at 08:54 AM.
-
March 7th, 2004, 09:02 AM
#2
Code:
printf("%d",strcmp(&temp[0],&string[0]));
or simply
Code:
printf("%d",strcmp(temp,string));
ng NoHero
-
March 7th, 2004, 09:08 AM
#3
Re: array character to character
Originally posted by winsonlee
Code:
printf("%d",strcmp(temp[0],string[0]));
temp[0] and string[0] are single char's, they are not pointer to const char. That is why you are getting the warning. You would note that this won't give you a warning.
Code:
printf("%d",strcmp(temp, string));
Note the difference?
I would like to compare some of the character between two strings. I would like to know how i can solved this problem. For your information, i would like the solution in C and not C++. Thanks
Code:
if ( temp[0] == string[0] )
You compare char's just like you compare int's, float's, long's or double's -- use ==.
If you want to compare an array of char with another array of char, then you must either write code that compares character by character, or use a function such as strcmp() or memcmp().
Regards,
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|