Re: segmentation fault
- From: Barry Schwarz <schwarzb@xxxxxxxxx>
- Date: Sun, 18 Jun 2006 22:07:13 -0700
On Sun, 18 Jun 2006 17:50:26 GMT, Andrew Poelstra
<apoelstra@xxxxxxxxxxxxxxxxxxxxx> wrote:
On 2006-06-18, Piotr S. <inri@xxxxxxxxxxxx> wrote:
What's wrong in following program:Lots.
#include <stdio.h>Why are you using a global?
#include <stdlib.h>
char s[80];
int main()int main (void) is better.
{*fopen()? Does that really compile unhindered? It doesn't make any sense,
FILE *fp, *fopen();
as fopen() is already defined in stdio.h.
It is only declared in stdio.h. Since this declaration is at
function/block scope, it serves to temporarily replace the declaration
in stdio.h only for code in this function/block.
if(fp = fopen("plik1","r")== NULL)What's wrong with return 1; or better, return EXIT_FAILURE;.
{
printf("blad otwarcia"); exit(1);
}While fgets returns a null string, print the null string? That can't be
else
{
printf("\notwarty\n");
while(fgets(s,30,fp)== NULL)
what you want.
It's even worse. While fgets returns a NULL pointer, attempting to
print the data pointed to invokes undefined behavior.
printf("%s\n",s);
}
}
I thought that buffor s is not properly declared, I had tried to declare
this variable
inside main(), and as char * s; Everytime runnig the program resulted in
segmentation fault.
I can imagine. You shouldn't try to printf a NULL pointer.
Remove del for email
.
- References:
- segmentation fault
- From: Piotr S.
- Re: segmentation fault
- From: Andrew Poelstra
- segmentation fault
- Prev by Date: Re: sizeof
- Next by Date: Re: sizeof
- Previous by thread: Re: segmentation fault
- Next by thread: Re: segmentation fault
- Index(es):
Relevant Pages
|