scanf、printf、putchar、getc、putc、fgets、fputs、sscanf、sprintffscanf和fprintf
fgets 从屏幕上获取输入(stdin)或者从文件中获取输入fputs 输入到屏幕上(stdout)或者输出到文件中.scanf 从屏幕上的输入格式化分离.printf 输出到屏幕上.sscanf 从字符串中格式化分离.sprintf 输出到字符串中.fscanf 从文件中格式化分离.fprintf 输出到文件中.fscanf%d%c%d可能导致的bug
#include<stdio.h>
#include<stdlib.h>#include<string.h>int count(int one, int tow, char symbol) { switch (symbol) { case '+': return one + tow; case '-': return one - tow; case '*': return one * tow; case '/': if (!tow) { return 0; } else { return one / tow; } }}
void main() { FILE*read = fopen("1", "r"); if (!read) { printf("文件为空"); system("pause"); return; }
FILE*write = fopen("1", "w");
int kong = NULL;
int xiaomiao = NULL; while (!feof(read)) { int one; int tow; char symbol; fscanf(read, "%d%c%d=\n", &one, &symbol, &tow); int shaomiao = ftell(read); if (shaomiao != kong) {int result = count(one, tow, symbol);
fprintf(write, "%d%c%d=%d\n", one, symbol, tow, result);
}
}fclose(read);
fclose(write); system("pause");}#include<stdio.h>
#include<stdlib.h>void main() { FILE*read = fopen("1.txt", "r"); if (!read) { printf("文件为空"); system("pause"); return; }int kong = NULL;
int xiaomiao = NULL; while (!feof(read)) { char name[20] = { NULL }; int age = NULL; fscanf(read, "%[^,],%d\n",&name,&age ); int shaomiao = ftell(read); if (shaomiao != kong) {printf( "名字%s,年龄%d\n",name,age);
}
}fclose(read);
system("pause");}