Z
Zach
I am getting 3 warnings I don't fully understand. My program works as
expected however I'd like to clear up these warnings and fix my code.
Here are the 3 warnings:
(I am compiling under gcc with "-W -Wall -std=c99 -pedantic")
count-tokens.c: In function ‘return_tokens’:
count-tokens.c:25: warning: comparison between signed and unsigned
count-tokens.c:27: warning: assignment makes pointer from integer
without a cast
count-tokens.c:29: warning: comparison between pointer and integer
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int numtokens = 0;
char *p;
char string[10] = "1 2 3 4 5";
int i;
int return_tokens(void);
int main(void)
{
printf("string length: %d\n",strlen(string));
return_tokens();
printf("Number of tokens: %d\n",numtokens+1);
return EXIT_SUCCESS;
}
int return_tokens(void){
for (i=0; i < (strlen(string) + 1); i++)
{
p = string;
if (p == ' ')
{
numtokens++;
}
else
{
p++;
}
}
return numtokens;
}
Regards,
Zach
expected however I'd like to clear up these warnings and fix my code.
Here are the 3 warnings:
(I am compiling under gcc with "-W -Wall -std=c99 -pedantic")
count-tokens.c: In function ‘return_tokens’:
count-tokens.c:25: warning: comparison between signed and unsigned
count-tokens.c:27: warning: assignment makes pointer from integer
without a cast
count-tokens.c:29: warning: comparison between pointer and integer
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int numtokens = 0;
char *p;
char string[10] = "1 2 3 4 5";
int i;
int return_tokens(void);
int main(void)
{
printf("string length: %d\n",strlen(string));
return_tokens();
printf("Number of tokens: %d\n",numtokens+1);
return EXIT_SUCCESS;
}
int return_tokens(void){
for (i=0; i < (strlen(string) + 1); i++)
{
p = string;
if (p == ' ')
{
numtokens++;
}
else
{
p++;
}
}
return numtokens;
}
Regards,
Zach