1
So basically the code needs to read the names of a txt file (AFTER I WILL MANIPULATE THEM) until it has the word 'end. In that part of the code where it reads the lines, it just stores the 1 string of the line and ignores the ones that come after and then it jumps the line to the next name. I need help reading the whole line and storing the names.
This part here that’s the problem, it separates the line into strings, but it’s just taking a string
aux = strtok(frase," ");
The file has these names:
Arya Meryn
Meryn Syrio
Brienne Stannis
Ellaria Myrcella
Jaime Aerys
Brienne Jaime
FIM
Code does not read 2 line names
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
int contador;
char *aux;
char frase[1000];
char *vetor[250];
char vetor2[200][200];
FILE *arquivo;
arquivo = fopen("nomes.txt","r");
contador = 0;
do{
fgets(frase,100,arquivo);
strlwr(frase);
aux = strtok(frase," ");
vetor[contador] = aux;
strcpy(vetor2[contador],vetor[contador]);
printf("-->%s\n",vetor[contador]);
contador ++;
}while(strcmp(frase,"fim")!=0);
contador --;
for(int i =0;i<contador;i++){
printf(" %s \n",vetor2[i]);
}
}