Targeting failure in C language

0

Hi, I have a problem ... The code only runs to a part after this appears:

Falha de segmentação (imagem do núcleo gravada)

Here's my program below:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int seleciona_indice (int array[], int tamanho)
{
    int i, rnd = rand() % tamanho;

    for (i = rnd + 1; i < tamanho; i++)
        array[i - 1] = array[i];

    return rnd;
}

void embaralhar (char *array[], int tamanho)
{
    int i;
    char *aux;
    int *listaIndices = malloc (tamanho * sizeof (int));

    srand (time (0));
    for (i = 0; i < tamanho; i++)
    listaIndices[i] = i;

    for (i = 0; i < tamanho - 1; i += 2)
    {
        int indiceA = seleciona_indice (listaIndices, tamanho - i);
        int indiceB = seleciona_indice (listaIndices, tamanho - i - 1);

        aux = array[indiceA];
        array[indiceA] = array[indiceB];
        array[indiceB] = aux;
        }
    free (listaIndices);
}

int main(void)
{

  char nome[23];
  int *data;
  printf("==============================\n");

  printf("          PARSENHA\n");

  printf("==============================\n");

  printf("Digite seu nome: ");
  scanf("%s", nome);
  printf("Digite sua data de nascimento: ");
  scanf("%d", data);
  embaralhar(nome, 23);
  printf("Senha forte: %s%ls" , nome, data);

  return 0;

}

    
asked by anonymous 13.11.2018 / 20:16

1 answer

2

gcc generates multiple warnings when compiling your code. Check the warnings and correct. But the error is occurring because you are trying to use an invalid pointer:

int *data;

in

scanf("%d", data);

Correct is to declare data as int :

int data;

and use:

scanf("%d", &data);
    
13.11.2018 / 20:33