-1

I want to initialize an array of strings with the same value to every position. So i am trying this code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#define TAM_VETOR 1009
#define QTD_PLACAS 1000

void inicializaVet(char * v[], int tamVet) {
    int i;
    for (i = 0; i < tamVet; i++) {
        printf("rodou %d\n", i);
        strcpy(v[i], "vazio");
    }
}

int main(void) {
    char vetor[TAM_VETOR][8];

    inicializaVet(vetor,TAM_VETOR);    

    return 0;
}

It does not work and can not copy even to the first position. (Prints "rodou 0" then breaks)

geraArquivo() is working.

I have tried to put the same code under the main function and it worked, i guess my mistake is on the types of arguments "inicializaVet" has? But i could not figure it out on my own.

Zan Lynx
  • 53,022
  • 10
  • 79
  • 131
LRD27
  • 98
  • 1
  • 8

1 Answers1

1

gcc -W -Wall provides a warning:

tmp-test.c:7:27: note: expected ‘char **’ but argument is of type ‘char (*)[8]’

You could pass the array as

void inicializaVet(char  v[TAM_VETOR][8], int tamVet) 

or as

void inicializaVet(char  v[][8], int tamVet) 
Zan Lynx
  • 53,022
  • 10
  • 79
  • 131
  • ... or as `void inicializaVet(char (*v)[8], int tamVet)`, just as your compiler says. This and your two are all 100% equivalent. – John Bollinger Nov 01 '18 at 02:51