Hi there,
I am having some problems prompting the user to enter a command in.
for example i want the command"print" to be recongised multiple time.
Its supposed to behave like this: Enter command > print
and then it prints out the contents of the file.
However when my program does this: Enter Command > print
print
and then it prints
i have to type print in 2 times for it to work. I been trying to figure what is the error but i cant see it.
Code:
char input[100];
fp = fopen(argv[1],"r");
while(fopen(argv[1],"r")){
printf("Enter command > ");
fgets(input,100,stdin);
if(strcmp(fgets(input,100,stdin),"print\n") == 0){
//i have another while loop with fgets to read stuff in file
}else if(strcmp(fgets(input,100,stdin),"quit\n") == 0)
fclose(fp); //closes program
}
}
reutrn 0;
}