I need help: / this program is supposed to look for a text in a txt file, if this text is there, then it generates another text and if that is not it writes it. for example:
Aleatoreamente gender INSERT INTO ALUM_PROF VALUES (2,4); And I look in the txt if this text is found, if it is not then I write it in the txt.
then generates INSERT INTO ALUM_PROF VALUES (5,7); I look for it in the txt, if it is not, I write it in the txt
then generates INSERT INTO ALUM_PROF VALUES (2,4); I look for it in the txt, as it is in it, so I do not write it and I generate another one again. and so
#include <stdlib.h>
#include <string.h> //strlen
#include <stdio.h>
int NUMEROS_AL_PROFE();
#define fila 100
int main()
{
char aux[200];
char aux2[200];
int contador=0;
FILE *f;
f = fopen("prueba.txt","a+");
if(f==NULL)
{
printf("no se ha podido abrir el archivo");
exit(1);
}
int i,num_prof,num_alum=1;
num_prof = NUMEROS_AL_PROFE();
fprintf(f,"INSERT INTO ALUM_PROF VALUES (%d,%d);\n",num_alum,num_prof); //escribo en el fichero f
num_alum++;
for(i=0;i<fila;i++)
{
num_prof = NUMEROS_AL_PROFE();
sprintf(aux,"INSERT INTO ALUM_PROF VALUES (%d,%d);\n",num_alum,num_prof); //almaceno el valor en aux
while(!feof(f))
{
fgets(aux2,200,f); //I read from the file f and I keep each line in aux2
if(strcmp(aux,aux2) == 0 ) //If a1 and a2 are equal then it is repeated.
{
contador=1;
}
memset(aux2, '#include <stdlib.h>
#include <string.h> //strlen
#include <stdio.h>
int NUMEROS_AL_PROFE();
#define fila 100
int main()
{
char aux[200];
char aux2[200];
int contador=0;
FILE *f;
f = fopen("prueba.txt","a+");
if(f==NULL)
{
printf("no se ha podido abrir el archivo");
exit(1);
}
int i,num_prof,num_alum=1;
num_prof = NUMEROS_AL_PROFE();
fprintf(f,"INSERT INTO ALUM_PROF VALUES (%d,%d);\n",num_alum,num_prof); //escribo en el fichero f
num_alum++;
for(i=0;i<fila;i++)
{
num_prof = NUMEROS_AL_PROFE();
sprintf(aux,"INSERT INTO ALUM_PROF VALUES (%d,%d);\n",num_alum,num_prof); //almaceno el valor en aux
while(!feof(f))
{
fgets(aux2,200,f); //I read from the file f and I keep each line in aux2
if(strcmp(aux,aux2) == 0 ) //If a1 and a2 are equal then it is repeated.
{
contador=1;
}
memset(aux2, '%pre%',200); //Vacio el array aux2
}
memset(aux, '%pre%',200);
if(contador==0)
{
fprintf(f,"INSERT INTO ALUM_PROF VALUES (%d,%d);\n",num_alum,num_prof);
}
num_alum++;
}
fclose(f);
}
//Random Number
int NUMEROS_AL_PROFE()
{
int num;
num = rand() % 17 + 1; //Numeros aleatorios entre 1 y 17
num = num + 1;
return num;
}
',200); //Vacio el array aux2
}
memset(aux, '%pre%',200);
if(contador==0)
{
fprintf(f,"INSERT INTO ALUM_PROF VALUES (%d,%d);\n",num_alum,num_prof);
}
num_alum++;
}
fclose(f);
}
//Random Number
int NUMEROS_AL_PROFE()
{
int num;
num = rand() % 17 + 1; //Numeros aleatorios entre 1 y 17
num = num + 1;
return num;
}
The program compiles and when executing it stays stuck and in the txt it does not write anything at first sight, but it fills up since it can weigh up to 1 gb, I have no idea what it is writing: l