Hey all, thanks for checking my topic
I need help with this -
Code:
#include <stdio.h>
#include <stdlib.h>
mostrar_menu ()
{
char option;
puts("\n\tAUTOMIBLES\n");
puts("0 - Exit");
puts("1 - Read TEXT file");
printf("Choose an option: ");
scanf("%c", &option);
switch(option)
{
case '0': puts("Goodbye"); break;
case '1': {ler_ficheiro(); break;}
default : { puts("Wrong option!\n"); mostrar_menu();}
}
}
/* -------------------------------------------------*/
int ler_ficheiro()
{
char s[30];
FILE *fp;
puts("Input file name: ");
gets(s);
gets(s);
fp= fopen(s, "r");
if (fp==NULL)
printf("Reading the %s file was not possible \n", s);
else
{
ler_fich_texto();
}
}
/* -------------------------------------------------*/
int ler_fich_texto(const char *fp)
{
int parametros;
int result;
FILE *stream;
char s;
parametros = 0;
fopen(fp, "r");
if ( stream )
{
parametros = 0;
while ( fgets(&s, 150, stream) )
{
++parametros;
}
fclose(stream);
printf(" %d parameters were read.\n", parametros);
}
else
{
printf("Error opening %s file!\n", fp);
result = 0;
}
mostrar_menu ();
}
/* -------------------------------------------------*/
main ()
{
int i=1;
while(i==1)
{
mostrar_menu();
i++;
}
}
So basically I'm using CYGWIN to compile my program - and I get a segmentation fault (core dumped) error.
What I want this to do is read a .txt (database) and tell me how many parameters are there in that file.
NOTE: Only option 0 and 1 are supposed to be working, the others are just so I don't forget.
The .txt I'm talking about is this one right here -
click
Any help would be nice, thanks!