Hey guys,
I'm starting computer science at uni this year and I'm teaching myself some C using online resources.
I'm trying to get a string input from a user in the console and save it into a char array, using scanf_s. This is what I have so far :
Code:
#include <stdio.h>
#include <string.h>
int main()
{
char str[50];
printf("Enter a word : ");
scanf_s("%s", str);
getchar();
return 0;
}
I used 'scanf_s' because I'm using visual studio and it forces you to. When I run the propgram, enter a string and press enter it crashes and I get a visual studio error (not an output error) that says :
Unhandled exception at 0x654D3FD4 (msvcr120d.dll) in Practice2.exe: 0xC0000005: Access violation writing location 0x00B70000.
When doing it with a single char and %c it's fine but when I try to save a string it crashes.
Weird thing is, even when copy+pasting working online examples of saving strings in this manner it crashes with this error message. I don't know if it's Visual Studio or something I'm missing. I've been trying different things for ages with no success . Any help would be great!
Cheers,
-Dinipants