小编Raj*_*med的帖子

写入和读取文件时出现SIGSEV错误

我正在编写代码来读写文本文件.但是当我运行我的代码时,我收到了一个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 …
Run Code Online (Sandbox Code Playgroud)

c runtime-error

0
推荐指数
2
解决办法
398
查看次数

标签 统计

c ×1

runtime-error ×1