What I want to do, is for the user to enter a text, then in the formaTabla
function that compares the string entered with the ones stored in the table and if the string is not repeated, save it in the table .
The problem I have is that when I execute it, it executes everything until it shows the string entered, then it does not work anymore. I would like to know if I have an error that I'm not really finding.
And I would like to know how is the syntax to reserve memory for an arrangement of structures, since I try it but it marks me error
struct tab
{ char cadena[25];
int alfa; };
char * ingresaCadena ();
struct tab* formaTabla (char *, int *filas);
int main()
{
char *texto,rta='s';
int filas=0,op;
struct tab *puntabla;
printf("Ingrese una de las siguientes opciones: \n");
printf(" 1-Ingresar texto y formar tabla \n 2-Buscar \n 3-Salir \n");
scanf("%d",&op);
while(getchar()!='\n');
while (op>0 && op<4)
{ switch (op)
{ case 1: while(rta=='s')
{ texto=ingresaCadena();
printf("El texto ingresado es: %s \n", texto);
puntabla=formaTabla(texto,&filas);
printf ("Desea ingresar otro texto? S o N \n");
scanf("%c",&op); }
for (int i=0; i<filas;i++)
{ printf("Las cadenas ingresadas son: \n");
printf("%s \n", *puntabla->cadena); } } }
system("PAUSE");
return 0;
}
char * ingresaCadena ()
{
char *t=(char*)calloc(25,sizeof(char));
printf("Ingrese el texto \n");
gets(t);
return t; }
struct tab* formaTabla (char *tex, int *f)
{
struct tab tabla[100];
int var,longi;
for (int i=0;i<=*f;i++)
{var=strcmp(tabla[i].cadena,tex);
if (var!=0)
{ strcpy(tabla[*f].cadena,tex);
longi=strlen(tabla[*f].cadena);
tabla[*f].alfa=longi;
*f++; } }
return (&tabla[*f-1]) ; }