home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!noc.near.net!ceylon!news.tufts.edu!jade.tufts.edu!slahiri
- From: slahiri@jade.tufts.edu (Sandip Lahiri)
- Newsgroups: comp.lang.c
- Subject: Re: Why won't this work?? (scanf(), etc.)
- Message-ID: <1992Dec21.182407.14093@news.tufts.edu>
- Date: 21 Dec 92 18:24:07 GMT
- References: <JVIGNEAU.92Dec10205719@cs.ulowell.edu>
- Sender: news@news.tufts.edu (USENET News System)
- Distribution: comp
- Organization: Tufts University - Medford, MA
- Lines: 32
-
- In article <JVIGNEAU.92Dec10205719@cs.ulowell.edu> jvigneau@cs.ulowell.edu (|Joe Vigneau|) writes:
- >This time I just can't figure it out... I am trying to build a binary tree,
- >with structures as nodes. This isn't the problem (yet...). The problem is that
- >I can't get scanf to work! This is the first time in the program that any sort
- >of input is called for, if there's a buffer problem or somethinf like that.
- >BTW: I'm using Ultrix and gcc.
- >
- >----trouble lies just ahead---------
- >struct Tree *starttree(void)
- >{ struct Tree *topnode;
- > char *last, *first, *mid;
- >
- > topnode = (struct Tree *)malloc(sizeof(struct Tree));
- >
- > if (topnode == NULL){
- > puts("starttree: malloc returned NULL");
- > exit(1);
- > }
- >
- > printf("First Name : "); scanf("%s",first);
- >/* ---------^
- > * The problem's right here.-| When the program gets this far, it dies and
- > * says "Bus error (core dumped)" I've tried using gets(), but that didn't
- > * work either. This is the problem.
-
- Allocate memory for first first. So the following would do,
- char first[100];
- Now, scanf("%s", first);
- will work. But my personal opinion is *not* to use scanf. Use fgets.
- Hope this helps.
-
- -Sandip
-