Mailing List ArchiveSupport open source code!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: tlug: gcc question
- To: tlug@example.com
- Subject: Re: tlug: gcc question
- From: "Scott M. Stone" <sstone@example.com>
- Date: Wed, 12 Jan 2000 15:08:37 -0800 (PST)
- Content-Type: TEXT/PLAIN; charset=US-ASCII
- In-Reply-To: <Pine.LNX.3.96.1000112114004.523B-100000@example.com>
- Reply-To: tlug@example.com
- Sender: owner-tlug@example.com
On Wed, 12 Jan 2000, Drew C. Poulin wrote: > Pardon me if this question is inappropriate for this list, but after > following it for several months, I thought someone might have a ready > answer. > > I'd like to continue to use gcc and xxgdb for some C classes I've > been taking, but I seem to have encountered a difference in how gcc > handles * char compared with how the MSVC++ compiler handles it. An > example is the code fragment below. gcc gives me a segmentation error when > it runs, while MSVC++ doesn't. Apparently the problem occurs when gets() > tries to access *lname at 0x0. I suppose there must be a good reason for > this. Can anyone tell me what it is and tell me how I should be handling > it? > > Thank you for any insight. ack! they let you hand in code like this in your school?? 1. your pointers are uninitialized. should be: char *fname=NULL; char *lname=NULL; 2. you're doing a gets() call into an unknown region of memory - doing the above should produce a segfault on any compiler, though, since it's known to be null -- unless you've initialized them as null, you have no idea where those things are pointing. 3. You need to allocate memory for the pointers: fname=(char *)malloc(80); lname=(char *)malloc(80); memset(fname,0,80); memset(lname,0,80); 4. You're using gets() at all. egcs will bitch about it and tell you not to use it, actually. what you really want in this case would be: fgets(fname,80,stdin); anyway, people (Chris) correct me if I'm wrong, but I think that the above is correct... > > Drew Poulin > > > #include<stdio.h> > > > main(){ > > char *fname, *lname; > > puts("Enter fname:\n"); > gets(fname); > puts("Enter lname:\n"); > gets(lname); > printf("First name: %s\tLast name: %s\n", fname, lname); > > } > > > ------------------------------------------------------------------- > Next Technical Meeting: January 14 (Fri) 19:00 > * Topic: "glibc - current status and future developments" > * Guest Speaker: Ulrich Drepper (Cygnus Solutions) > * Place: Oracle Japan HQ 12F Seminar Room (New Otani Garden Court) > ------------------------------------------------------------------- > more info: http://www.tlug.gr.jp Sponsor: Global Online Japan > -------------------------- Scott M. Stone, CCNA <sstone@example.com> UNIX Systems and Network Engineer Taos - The SysAdmin Company ------------------------------------------------------------------- Next Technical Meeting: January 14 (Fri) 19:00 * Topic: "glibc - current status and future developments" * Guest Speaker: Ulrich Drepper (Cygnus Solutions) * Place: Oracle Japan HQ 12F Seminar Room (New Otani Garden Court) ------------------------------------------------------------------- more info: http://www.tlug.gr.jp Sponsor: Global Online Japan
- Follow-Ups:
- Re: tlug: gcc question
- From: Christopher Sekiya <wileyc@example.com>
- References:
- tlug: gcc question
- From: "Drew C. Poulin" <poulin@example.com>
Home | Main Index | Thread Index
- Prev by Date: Re: tlug:
- Next by Date: Re: tlug: gcc question
- Prev by thread: Re: tlug: gcc question
- Next by thread: Re: tlug: gcc question
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links