S
Shuaib
The following simple code gives an error of: "Segmentation fault" just
as I press Enter after entering a word. Any idea why this might be
occuring?
I am using GCC to compile the programe. Here is an output of $gcc
--version
gcc (GCC) 3.3.5-20050130 (Gentoo 3.3.5.20050130-r1,
ssp-3.3.5.20050130-1, pie-8.7.7.1)
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
=========CODE=========
#include <stdio.h>
int main()
{
printf("Enter a word: ");
char word[20];
scanf("%s", word);
printf("%s", word);
FILE *file;
file=fopen("file1", "r+");
fclose(file);
return 0;
}
=========CODE==========
as I press Enter after entering a word. Any idea why this might be
occuring?
I am using GCC to compile the programe. Here is an output of $gcc
--version
gcc (GCC) 3.3.5-20050130 (Gentoo 3.3.5.20050130-r1,
ssp-3.3.5.20050130-1, pie-8.7.7.1)
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
=========CODE=========
#include <stdio.h>
int main()
{
printf("Enter a word: ");
char word[20];
scanf("%s", word);
printf("%s", word);
FILE *file;
file=fopen("file1", "r+");
fclose(file);
return 0;
}
=========CODE==========