Hii,
when I run this program using GCC there is no compilation error but I get segmentation error. Please help me
#include<stdio. h>
#include<string .h>
int main()
{
FILE *fp;
char *filename();
if ((fp = fopen (filename(),"r" )) == NULL)
{
printf ("File could not be opened\n");
// error_handler() ;
}
else
{
printf ("file opened");
}
}
char *filename() /* return filename */
{ static char *filenm = ".............. ..........";
do
{
printf ("Enter filename :");
scanf ("%24s",&filenm );
// skipgarb();
}
while (strlen(filenm) == 0);
return (filenm);
}
when I run this program using GCC there is no compilation error but I get segmentation error. Please help me
#include<stdio. h>
#include<string .h>
int main()
{
FILE *fp;
char *filename();
if ((fp = fopen (filename(),"r" )) == NULL)
{
printf ("File could not be opened\n");
// error_handler() ;
}
else
{
printf ("file opened");
}
}
char *filename() /* return filename */
{ static char *filenm = ".............. ..........";
do
{
printf ("Enter filename :");
scanf ("%24s",&filenm );
// skipgarb();
}
while (strlen(filenm) == 0);
return (filenm);
}
Comment