0
I have this simple code in C language that gets an input value and returns the value on the screen. Instead of showing the string on the screen, it shows symbols like bars. When I do the procedure with integer numbers, it shows the value correctly, the error only occurs when I do with strings.
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int main(void)
{
char nome[61];
printf("Digite seu nome: ");
scanf_s("%s", nome);
printf("O nome armazenado foi: %s", nome);
//getch();
return 0;
}
scanf_s? use scanf only
– Paulo Martins
Here generates access violation exception when recording.
– RHER WOLF
when using scanf it shows an error.
Erro C4996: 'scanf': esta função ou variável pode não ser segura. Considere usar scanf_s em vez disso. Para desativar a suspensão de uso, use _CRT_SECURE_NO_WARNINGS. Consulte a ajuda online para obter detalhes.
Inseri #define _CRT_SECURE_NO_WARNINGS before includes and worked. Thanks!– Ricardo Baltazar
The
scanf_s
is a variant of Microsoft to specify amount of input read and avoid buffer overflow Attack. This means that your reading is wrong because the size of the reading is missing.– Isac