#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE *fp;
char str[80];
int i;
if((fp = fopen("test","w")) == NULL)
{
printf("不能打开文件。\n");
exit(0);
}
printf("Please enter a string and a number:\n");
fscanf(stdin, "%s %d", str, &i);
fprintf(fp, "%s %d",str, i);
fclose(fp);
if((fp = fopen("test","r")) == NULL)
{
printf("不能打开的文件.\n");
exit(0);
}
fscanf(fp, "%s %d", str, &i);
fprintf(stdout, "%s %d\n", str, i);
fclose(fp);
system("pause");
return 0;
}
|