2
I need to read a text file and store each word of the file in a vector position. The reading was done normally and the file was passed by parameter such as the amount of words.
The code performs the storage in a strange way. When I try to print, a rain of random characters appears.
Code:
void armazena_vetor(FILE* dicionario, int numero_palavras) //armazena o dicionario em um vetor
{
char vetor_palavras[numero_palavras][15];
int posicao;
int i;
posicao = 0;
printf("%d", numero_palavras);
while(((fscanf(dicionario, "%s", vetor_palavras[posicao])) != EOF) && (posicao < numero_palavras)) //Escreve uma palavra em cada posicao do vetor
{
posicao++; //Incremento de posicao
}
for (i=0;i<numero_palavras;i++) //teste imprime
{
printf("%s \n", vetor_palavras[i]);
}
}
How this file structure your containing words?
– gato
It is a dictionary.txt: Pineapple Avocado.... . . . Where words are separated by " n"
– D_Alves
Yes, like this organized the words in the archive, in list?
– gato
Post your code calling your function
armazena_palavra
.– gato