How to use "fread","write","seek",counter to write a interactive talk in C,save in a file?
write initial question and all approriate "questions" from a state machine to screen
also write all "questions" and keyboard input "answers" to a new disk file
read the keyboard input answer from the disk file,check a state machine and responds appropriately a new question
If console type in "Exit", then stop.
Sample output on screen is same as the created disk file, looks like below:
User: “Knock Knock”
Machine: “Who is There?”
User: “Mike.”
Machine: “Mike Who?”
User: “Mike who deliever a pizza.”
Machine: “Cool.”
...
User: “Exit”
Machine: “I am out”
My code:
int main()
{ FILE *fp=fopen("test","a"); char s[256]; scanf("[^\n]",s); While (s!="Exit"){ fwrite("User:"+s,10,25,fp); responde(s); } fwrite("User:"+,10,25,fp); fwrite("Machine: i am out",10,25,fp); exit(0); } void respond(char* s){ if(s=="Knock Knock"){ printf("Machine:who is there"); fwrite("MAchine:who is there,10,25,fp); } if???? {printf("Machine: %s,who\n+User:",s); fwrite(""Machine: %s,who\n+USer",10,25,fp); } if (???)