小编Elo*_*din的帖子

多个fscanf

我编写了以下程序,用于将文件中的字符串读入变量"title":

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int m, b;
    char *title;
    FILE *fp;

    fp = fopen("input2.txt", "r");
    if (fp == NULL)
    {
         printf ("Error: file cannot be found\n");
         return 1;
    }

    fscanf(fp, "<%d>\n<%d>", &m, &b);
    printf("%d\n%d", m, b);
    fscanf(fp, "<%s>", title);

    fclose(fp);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

上面的程序在第二次调用时崩溃了fscanf.为什么会这样?

c arrays pointers scanf buffer-overflow

1
推荐指数
1
解决办法
475
查看次数

标签 统计

arrays ×1

buffer-overflow ×1

c ×1

pointers ×1

scanf ×1