I have a question of how to store in a variable of type char
a name among several saved in a binary file in C language, besides that the name is selected in a random way, to then show the name saved by means of the variable
this is the code:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(){
int cont=0,num;
srand(time(NULL));
char aux[50];
FILE *archivo;
num=rand()%51;
archivo=fopen("doc.dat","rb");
if(archivo==NULL){
printf("Error de apertura");
}
while(!feof(archivo)){
cont++;
if(cont==num){
fgets(aux,50,archivo);
}
}
fclose(archivo);
printf("%s",aux);
}
and the binary file has the following saved:
Son GokuVegetaSon GohanSon GotenTrunksKrilinFreezerYamchaTen Shin HanGoku BlackBob EsponjaCalamardoDon CangrejoPatricio EstrellaYugi MutoAangZukoETAlfDanny PhantomBruce WayneDick GraysonJason ToddTim DrakeDrake ParkerJosh NicholsClark KentCrash BandicootSonic El ErizoShadow El ErizoJason VoorheesPamela VoorheesFreddy KruegerHomero J SimpsonBart SimpsonLisa SimpsonMoe SzyslakBarney GomezDraculaVictor FrankensteinHombre LoboHarry PotterMarioLuigiPrincesa PeachToadBowserLinkPrincesa ZeldaGanondorf