Visual Studio 2013 C语言//编写文件//崩溃

时间:2015-04-09 18:23:03

标签: c file visual-studio-2013 writing

// This code should run
// When I run the code, I get the prompt to enter a number then when I press enter it crashes. File.exe stopped working or
// Unhandled exception at 0x0FBFE541 (msvcr120d.dll) in File.exe: 0xC0000005: Access violation writing location 0x00000000.

#include<stdio.h>
#include<conio.h>

void main()
{

    int n = 0;
    FILE *f;

    fopen_s(&f, "text.txt", "r+");

    if (f == NULL)
            printf_s("Error!");

    printf_s("Enter a number: ");
    scanf_s("%d", n);

    fprintf_s(f, "%d", n);


    fclose(f);

    _getch();
}

0 个答案:

没有答案