I'm having a question on how to split information from a text file into variables in C. Example, I have a txt file with the following data:
3 2
A
D
E
AD
DE
I would like to read this file, and separate each information into a variable, for example, the number 3 in a variable, the 2 in another, A in another and so on, the letters together can be in a variable only.
So far what I got in terms of code was this:
void ler_arquivo(){
int vertices;
int arestas;
FILE *arq = fopen("init.txt","r");
if(arq != NULL){
printf("\tSucesso!\n");
char linha[3];
while(!feof(arq)){
fgets(linha,3,arq);
printf("%s",linha);
}
}
}
For now I'm just printing the vector, because I do not know how to do the division into variables.