C语言中fscanf的莫名报错

软件为CLion。

功能需要从文件中读取整数浮点数和字符串,按照书上写的fscanf函数。代码如下

#include <stdio.h>
int main()
{
    FILE *open;
    open=fopen("test.txt","w");
    int i=123123;
    fprintf(open,"%d",i);
    printf("%d",i);
    fclose(open);
    open=fopen("test.tst","r");
    fscanf(open,"%d",&i);
    printf("%d",i);
    fclose(open);
    return 0;
}

运行后没有输出,只有一行报错

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

把fscanf那行注释掉就可以正常输出。

可能是我理解不够透彻,望各位不吝赐教,或者有更方便地读取方法用来替代也可以

看看这些相关博客: https://blog.csdn.net/weixin_40490238/article/details/103627889 

发现了,第二次打开时是.tst