[comp.unix.programmer] Segmentation fault

subbarao@phoenix.Princeton.EDU (Kartik Subbarao) (02/25/91)

In article <38191@netnews.upenn.edu> widyono@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@phoenix.Princeton.EDU -| Internet
kartik@silvertone.Princeton.EDU (NeXT mail)  
SUBBARAO@PUCC.BITNET			          - Bitnet