-3

Here is the code, he is causing the crashes but he is pretty simple:

int main() {

char* nome;
printf("Digite seu nome:  ");
scanf("%s",&nome);
printf("O nome digitado foi %s \n",nome);

return 0; }

0 warning, but the console crash after I type a simple word.

Rodrigo H
  • 7
  • 2

1 Answers1

1

nome is an uninitialized pointer, and you're trying to store a string there. But there is no "there", so you get undefined behavior.

Try:

char nome[128];

that will give you some space. This is still dangerous (no limit to how much scanf() will store), but should take you one step further.

unwind
  • 391,730
  • 64
  • 469
  • 606
  • 1
    also `scanf("%s",&nome);` should be `scanf("%s",nome);` (even if it works with a char array) – Jean-François Fabre Jun 13 '17 at 12:54
  • I bought a beginner book and he said the other way to me, people are fast to say "read a book" even if you're trying, for example, @SouravGhosh is the least helpful user in this site. I will try to buy another book. – Rodrigo H Jun 13 '17 at 12:57