Visual Studio error in C

-1

I'm new to C programming and I am currently reading through the Tony Royce C programming book and I am doing the exercises using Microsoft Visual studio 2015. I have code for one of them.

#include "stdafx.h"


int main();

    char student_name[11];
    int mathsmark = 0;
    int englishmark = 0;
    int computingmark = 0;
    int averagemark = 0;

    printf_s("Please key in your name:\n");
    scanf_s("%s", student_name);

    printf_s("Please key in your English Mark:\n");
    scanf_s("%d", englishmark);

    printf_s("Please key in your Maths Mark:\n");
    scanf_s("%d", mathsmark);

    printf_s("Please key in your Computing Mark:\n");
    scanf_s("%d", computingmark);

    averagemark = englishmark + mathsmark + computingmark / 3;

    printf_s(student_name, "Your average mark is %d", averagemark);



    getchar();
    return 0;
}

When I run this code however it comes up with this error:

"Exception thrown at 0x0F830B5C (ucrtbased.dll) in Tonyroycestuff.exe: 0xC0000005: Access violation writing location 0x00500000. If there is a handler for this exception, the program may be safely continued."

And if I press continue it comes up with this error:

"Unhandled exception at 0xFEFEFEFE in Tonyroycestuff.exe: 0xC00001A5: An invalid exception handler routine has been detected (parameters: 0x00000003)."

I'm not sure why and I was wondering if someone could help me with this, any help would be greatly appreciated!

c
asked on Stack Overflow Oct 26, 2016 by LoneWolf • edited Oct 26, 2016 by jaggedSpire

1 Answer

1

You need to call scanf_s as:

    scanf_s("%d", &englishmark);

... and similarly for the other int values.


User contributions licensed under CC BY-SA 3.0