<分区>
我正在编写代码来读取和写入文本文件。但是当我运行我的代码时,我遇到了 SIGSEGV 运行时错误。我需要帮助找出代码有什么问题。
#include <stdio.h>
#include <stdlib.h>
int main(){
/*Variable for writing to file */
char *name[] = {"Raju", "Nayan", "Hanif"};
char *id[] = {"100", "101", "102"};
float cgpa[] = {3.50, 5.00, 4.00};
/*Variable for reading from file*/
char *getname, *getid;
float getcgpa;
int i;
FILE *fp;
fp = fopen("f:\\raju.nog", "w"); /*Create new file */
for(i=0; i<5; i++){
fprintf(fp, "%-10s%-10s%-1.2f\n", name[i], id[i], cgpa[i]); /*write to file*/
}
fclose(fp);
/*read from file and print to screen*/
fp = fopen("f:\\raju.nog", "r");
while(fscanf(fp, "%s %s %f", &getname, &getid, &getcgpa) != EOF){
printf("%-10s%-10s%-1.2f\n", getname, getid, getcgpa);
}
system("PAUSE");
}