Hey everyone,
I have a code here with me and I'm having trouble putting my conditions.
I'm basically putting a string and I have to split it into 4 and atoi to change a char to an int but basically when I run the program failed.
It tells me "Ordered comparison between pointer to integer (char to int)"
Have a look at it. The problem is my condition I put.
void check_word(char word);
void check_year(int year);
void check_definition(char definition);
void check_synonyms(char synonym);
//------------------------------------------------------------------//
// SPLITTING THE STRING
//------------------------------------------------------------------//
char *split(char words[100])
{
int i = 0;
char* words_dup = malloc(strlen(words)+1);
strcpy(words_dup,words);
while (words!='\0')
{
char *word=strtok(words, "_#_");
check_word(*word);
char *year=strtok(NULL, "_#_");; // assigning NULL for previousely where it left off
i=atoi(year);
check_year(i);
char *definition=strtok(NULL,"_#_");
check_definition(*definition);
char *synonyms=strtok(NULL,"_#_");
check_synonyms(*synonyms);
printf("%s\t", word);
printf("%i\t",i);
printf("%s\t", definition);
printf("%s\t", synonyms);
}
// now restore words
strcpy(words,words_dup);
free(words_dup);
return 0;
}
//------------------------------------------------------------------//
// CHECKING LEGAL OR NOT
//------------------------------------------------------------------//
void check_word(char word)
{
if (word>='A' && word<='Z')
{
printf("not legal\n");
}
}
void check_year(int year)
{
if (year<0)
{
printf("not legal\n");
}
}
void check_definition(char definition)
{
if (definition>='A' && definition<='Z')
{
printf("not legal\n");
}
}
void check_synonyms(char synonym)
{
if (synonym>='a' && synonym<='z')
{
printf("not legal\n");
}
}
int main()
{
char words[100];
printf("Enter a string\n");
scanf("%s", words);
split(words);
}
The string that I'm trying to input is:
hello_#2003#my#_Name
Any help?