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: Mike Fabian <mike.fabian@example.com>
- Date: 12 Jan 2000 23:28:02 +0100
- Content-Type: text/plain; charset=us-ascii
- In-Reply-To: "Drew C. Poulin"'s message of "Wed, 12 Jan 2000 11:55:55 -0800 (PST)"
- References: <Pine.LNX.3.96.1000112114004.523B-100000@example.com>
- Reply-To: tlug@example.com
- Sender: owner-tlug@example.com
- User-Agent: Gnus/5.0804 (Gnus v5.8.4) XEmacs/21.1 (Bryce Canyon)
"Drew C. Poulin" <poulin@example.com> writes: > 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. [...] > #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); > > } you might want to make sure that `fname' and `lname' point somewhere where you have allocated some space, big enough to hold the strings you want to enter. For example: char fname[1024]; char lname[1024]; should work. Or use malloc(). And better don't use `gets'. Quote from the libc.info file: *Warning:* The `gets' function is *very dangerous* because it provides no protection against overflowing the string S. The GNU library includes it for compatibility only. You should *always* use `fgets' or `getline' instead. To remind you of this, the linker (if using GNU `ld') will issue a warning whenever you use `gets'. -- Mike Fabian <mike.fabian@example.com> <mike@example.com> ------------------------------------------------------------------- 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
- References:
- tlug: gcc question
- From: "Drew C. Poulin" <poulin@example.com>
Home | Main Index | Thread Index
- Prev by Date: Re: tlug: gcc question
- Next by Date: Re: tlug: gcc question
- Prev by thread: Re: tlug: gcc question
- Next by thread: tlug: Re: gcc question
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links