Tag: 文件

而((c = getc(file))!= EOF)循环不会停止执行

我无法弄清楚为什么我的while循环不起作用。 代码在没有它的情况下正常工作……代码的目的是在bin文件中查找秘密消息。 所以我得到了代码来找到这些字母,但现在当我试图让它循环到文件的末尾时,它不起作用。 我是新来的。 我究竟做错了什么? main(){ FILE* message; int i, start; long int size; char keep[1]; message = fopen(“c:\\myFiles\\Message.dat”, “rb”); if(message == NULL){ printf(“There was a problem reading the file. \n”); exit(-1); } //the first 4 bytes contain an int that tells how many subsequent bytes you can throw away fread(&start, sizeof(int), 1, message); printf(“%i […]

C,从文件读入结构

几天来我一直在努力,我无法弄清楚为什么它不起作用。 我正在尝试从文件中读取带有这样的数字的数字: 0 2012 1 1 2000.000000 0 2012 1 1 3000.000000 1 2012 1 1 4500.000000 我的结构: struct element{ int id; int sign; int year; int month; double amount; struct element *next; }; struct queue{ struct element *head; struct element *tail; struct element *head2; struct element *temp; struct element *temph; int size; }; (head2,temp和temph用于排序结构) […]

将文本文件中的数字读入C中的数组

我是编程菜鸟所以请耐心等待。 我正在尝试将文本文件中的数字读入数组。 文本文件“somenumbers.txt”只包含16个数字,如“5623125698541159”。 #include main() { FILE *myFile; myFile = fopen(“somenumbers.txt”, “r”); //read file into array int numberArray[16]; int i; for (i = 0; i < 16; i++) { fscanf(myFile, "%d", &numberArray[i]); } for (i = 0; i < 16; i++) { printf("Number is: %d\n\n", numberArray[i]); } } 该计划不起作用。 它编译但输出: 编号是:-104204697 数字是:0 编号是:4200704 编号是:2686672 编号是:2686728 […]