silviatodorof
Programmer
- Dec 31, 2011
- 2
This is a portion of a program:
/******************************************************/
if((fp = fopen("Taxi Information.txt", "w"))==NULL) {
printf("Cannot open file.\n");
exit(1);
}
do {
printf("Please enter the car name(CR to quit):\n");
scanf_s("%s",carname);
fflush(stdin); gets(carname);
strcat(carname, "\n");/*add a newline */
fputs(carname,fp);
} while(*carname!='\n');
/******************************************************/
I had a problem with suing scanf_s and gets together. The problem was: I was stuck with the carname and cann't get out of it.
I looked for a solution in the net and found out that using fflush between scanf and get can solve the problem, but this created a new problem. The problem is that fflush caused the text file to be empty.
Thanks
/******************************************************/
if((fp = fopen("Taxi Information.txt", "w"))==NULL) {
printf("Cannot open file.\n");
exit(1);
}
do {
printf("Please enter the car name(CR to quit):\n");
scanf_s("%s",carname);
fflush(stdin); gets(carname);
strcat(carname, "\n");/*add a newline */
fputs(carname,fp);
} while(*carname!='\n');
/******************************************************/
I had a problem with suing scanf_s and gets together. The problem was: I was stuck with the carname and cann't get out of it.
I looked for a solution in the net and found out that using fflush between scanf and get can solve the problem, but this created a new problem. The problem is that fflush caused the text file to be empty.
Thanks