Visual Studio error in C, unhandled exception at 0xfefefefe

2

I am learning how to write C in Visual Studio, and here is my code,

#include<stdio.h>

int main() {
    char me[20]; 

    printf("What is your name?");
    scanf_s("%s", me);
    printf("darn glad to meet you, %s!\n", me);

    return(0);
}

Now, after typing all that in I get an error popping up "Unhandled exception at 0xFEFEFEFE in Project14.exe: 0xC00001A5: An invalid exception handler routine has been detected (parameters: 0x00000003)"

c
windows
visual-studio-2012
c11
tr24731
asked on Stack Overflow Jun 6, 2015 by user147271 • edited Apr 18, 2018 by Deduplicator

1 Answer

3

You're using scanf_s() wrong. The way described in MSDN is scanf_s("%s", me, sizeof me);

Also you really should check the return value of the function

if (scanf_s("%s", me, (unsigned)sizeof me) != 1) /* error */;

Also note that the MSDN description and the C11 Standard description only have minor differences except that MSDN fails to inform you the function is optional for Standard compliant implementations. If you intend to run your code in other than Windows, you may want to add checks for the existence of the function or use some other way to get user input.

#ifdef __STDC_LIB_EXT1__
// use Annex K functions at will
#else
// do not use Annex K functions
#endif
answered on Stack Overflow Jun 6, 2015 by pmg • edited Jun 6, 2015 by pmg

User contributions licensed under CC BY-SA 3.0