Thanks for the reply guys!
new code
Code:
#include <stdio.h>
#include <string.h>
int main()
{
//Open the file for reading
FILE *in = fopen("CommandsProj1.dat", "r");
//fgets buffer
char buffer[100];
//Pieces of string tokenized
char * stringPiece;
//int for comparing strings
int compare=2;
//While loop. Getting lines from file
while ( fgets(buffer, sizeof(buffer), in) != NULL ){
fgets(buffer, 100, in);
// printf("%s\n", buffer);
stringPiece = strtok (buffer," ");
while (stringPiece != NULL){
printf("%s\n",stringPiece);
compare=strcmp(stringPiece,"H");
if (compare==0){printf("HELP");}
//printf("%s\n",stringPiece);
stringPiece = strtok (NULL, " ");
}
}
//Close file
fclose(in);
return 0;
}
I put in the strcmp() function, and still;
I print out stringPiece, it shows up as H but when I compare it, it doesn't seem to be the same.
Am I doing something wrong with the compare?
does the string from strtok() have a different structure or something than the "H"?
Also,
When I'm using
while ( fgets(buffer, sizeof(buffer), in) != NULL )
it only prints out halfway through the .dat file.
(will keep on looking into that and try to fix it)
Thanks for the time taken to help me out
Lolo