Segmentation fault
Kartik Subbarao
subbarao at phoenix.Princeton.EDU
Mon Feb 25 12:21:28 AEST 1991
In article <38191 at netnews.upenn.edu> widyono at eniac.seas.upenn.edu (Aasmodeus) writes:
>
>Hello. I've got a problem that needs a fast solution, fast! Examine the
>following bits of code:
>
>int getline(FILE *fp, char *line); /* decl. should it be line[]? */
>main(int argc, char *argv[])
>{
> char line[BUFSIZ]; /* line of input */
> while (getline(fp, line) > 0) {
> printf("%s\n", *line);
Here's the problem -- when you have a %s in the format string, printf
wants a POINTER to the string, not the first character in it.
printf tries to interpret the first character in line as the address of
the beginning of the string. Because that first character is in the range
0 thru 128, the program segfaults.
>In the case of the above, the error comes in _doprnt.
right. just as it should. Another problem may be the fact that you don't
assign fp to be anything.
-Kartik
--
internet# find . -name core -exec cat {} \; |& tee /dev/tty*
subbarao at phoenix.Princeton.EDU -| Internet
kartik at silvertone.Princeton.EDU (NeXT mail)
SUBBARAO at PUCC.BITNET - Bitnet
More information about the Comp.unix.programmer
mailing list