So below is my code, the "if" statement (line marked by comment for referrence) doesn't work if strcpy() is present inside it even the "if" condition evaluates to true. The strange thing is that when the strcpy() is moved out the "if" statement, the "if" statement works perfectly fine.
int check_state(char curr[], char next[]); //Returns 1 or 0 based some logic which is irrelevant here
int main()
{
char curr[25], next[25], tmp;
scanf("%c",&tmp);
scanf("%s",curr);
int scalar=0, vector=0;
while (1) {
scanf("%s",next);
if (!strcmp(next,"EOF")) break;
if (check_state(curr,next)){ //This is the "if" statement which doesn't work if the strcpy() is kept inside the statement
if (!strcmp(next,"scalar-state"))
scalar++
else if (!strcmp(next,"vector-state"))
vector++;
strcpy(curr,next); //this is the strcpy() i am talking about
}
//if i move the above strcpy() here, everything works perfectly
}
printf("%d %d",scalar,vector);
return 0;
}
Aucun commentaire:
Enregistrer un commentaire