Mini Akinator - allocate line by line.txt file in vector

Asked

Viewed 30 times

1

I am improving a code I made for a college job. A very simplified version of Akinator. Before I did everything in the main code, now I want to read the characters of a txt file. I already created the file and already filled with the options, only now I need to take specific lines from the file to print and manipulate the rest of the code. Follow what I’ve done.

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

int main(){

    FILE *personagens;
    personagens = fopen("personagens.txt", "r");

    //fprintf(personagens,"Son Goku\n"); -> escrever no arquivo

    char modpersonagens[100];

    while(fgets(modpersonagens, 100, personagens) != NULL){
        printf("%s", modpersonagens);
    }
    fclose(personagens);

    return 0;
}
  • Your doubt is like reading several characters one for each line in the file?

  • Yes, I want to put each character in a vector place, so I can manipulate them.

  • The text file is formatted with word n, word n

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.