Tag: 读取

使用C中的fscanf()读取文件

我需要从文件中读取和打印数据。 我写的程序如下, #include #include int main(void) { char item[9], status; FILE *fp; if( (fp = fopen(“D:\\Sample\\database.txt”, “r+”)) == NULL) { printf(“No such file\n”); exit(1); } if (fp == NULL) { printf(“Error Reading File\n”); } while(fscanf(fp,”%s %c”,item,&status) == 1) { printf(“\n%s \t %c”, item,status); } if(feof(fp)) { puts(“EOF”); } else { puts(“CAN NOT READ”); } getch(); […]