samedi 27 novembre 2021

Trying to find a specific text line inside a file

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

void sorteia_palavra(char *palavra)
{
    char palavra[128];
    int n;
    int rand_number;
    open = fopen("palavras.txt", "r");
    fscanf(open, "%d", &n);
    rand_number = rand() % n;
    fclose(open);
}

// here i will try to add some context, basically, what this function is supposed to do is, i will get a number from the first line of the text, that has an integer that says the amount of words are inside the text, inside the text every line has one single word, basically, i have to use that first number that i get from the text file, and choose a random number between 0 and that number, and then use this number to choose one singular word from inside the file, what i'm trying to do, wich i'm failing, is to usee fseek to point in a place of memory, and get a word from that place, if anyone can help me find a better way on how to do what i want, i'm very thankful for that :)




Aucun commentaire:

Enregistrer un commentaire