LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-09-2003, 08:24 AM   #1
surya123
LQ Newbie
 
Registered: Jul 2003
Location: Bali-Indonesia
Distribution: local
Posts: 11

Rep: Reputation: 0
i need gcc manual


i found error messages like this : Segmentation fault (Core dumped) when i compile it:"gcc LIFO.c" then run it:
"./a.out <sedikit.txt"
notes:
i use redhat 7.0
sedikit.txt is textfile, it contains:
abjad
anggur
baku
bento
laskar
tugas
tunas

i'd like to insert every text to be LIFO, but in the early i got problem like that???

listing:
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>

struct reckey
{
char *name;
struct reckey *next;
};
typedef struct reckey pkey;

int main()
{
pkey *header;
pkey *nodeBaru;
char *S;

header = (pkey *)0;

while (fgets(S,30,stdin))
{
printf("%s",S);
}
}

i need manual to learn more about gcc. Do you know where (address of http/url) can i find it?
thanks before.
 
Old 07-09-2003, 09:00 AM   #2
TheLinuxDuck
Member
 
Registered: Sep 2002
Location: Tulsa, OK
Distribution: Slack, baby!
Posts: 349

Rep: Reputation: 33
AFA what the code is trying to do, the problem here is that you've created a pointer to a memory location (char *S), and are assigned data to it (fgets(S, 30, stdin)) before any actual heap space is assigned to the pointer (*S). In order to use the space at *S, you need to allocate it first. There are two ways to go about this:

Code:
//  staticly define S as a string, with 30 characters of space
char S[30];
  ...
  fgets(S,30,stdin);
or

Code:
 // dynamically assigned memory space for input
char *S;

S = (char *)malloc(sizeof(char) * 30);
if(S == NULL)
  perror("Unable to malloc space for S");
else {
  fgets(S,30,stdin);
  printf("%s", S);
}
One of those options should solve your segfault problem.

Oh, and anytime you post code here, please surround the code with [code] [/code] tags, so that it will look nice, and be easier to read (preserving indentations) as above.

(=

Last edited by TheLinuxDuck; 07-09-2003 at 09:02 AM.
 
Old 07-09-2003, 10:20 AM   #3
dakensta
Member
 
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194

Rep: Reputation: 35
The gcc manual is here:

http://gcc.gnu.org/onlinedocs/

but it won't teach you C
 
Old 07-09-2003, 11:45 AM   #4
captainstorm
Member
 
Registered: Jun 2003
Location: Oricola, Italy
Distribution: RH 9, so far
Posts: 261

Rep: Reputation: 31
I like the second solution, seems to be traditional.

Qu Chen
 
Old 07-09-2003, 06:43 PM   #5
surya123
LQ Newbie
 
Registered: Jul 2003
Location: Bali-Indonesia
Distribution: local
Posts: 11

Original Poster
Rep: Reputation: 0
i have reply these, but where can i view it?
i pressed submit reply then this forum ask to re-login then i dont know where my reply gone?

test test.. (i'll click Submit Reply button)
 
Old 07-09-2003, 06:54 PM   #6
surya123
LQ Newbie
 
Registered: Jul 2003
Location: Bali-Indonesia
Distribution: local
Posts: 11

Original Poster
Rep: Reputation: 0
oh i understand now..
when i re-login, this forum can not submit my reply..

thanks @e
next i'll send it by
Code:
 and
, cause i'm sure i'll have many problems in programming..

i'm trying make Last In First Out link list to text file but when i test to compile it, it occured that error message.
my basic is pascal programming, so i found myself in trouble when learn gcc.. huff

about these site http://gcc.gnu.org/onlinedocs/
yap, u r right, it wont teach me gcc, i have viewed before.

thank all, i'll try it again..
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
gcc wont install, 'failed dependencies: glibc-devel is needed by gcc-3.3.3-41' TdlSnare SUSE / openSUSE 3 11-29-2004 02:13 PM
Kernel compiling: gcc-3.3 is 586, should be gcc-3.3 386 Erik Plaggenmar Linux - Software 0 10-01-2004 11:38 AM
running software built with gcc 3.0.2 on Redhat 8 - gcc 3.2 dst1989 Linux - Software 3 03-08-2004 10:23 PM
a doubt with host gcc and arm-linux-gcc renjithgopal Linux - General 1 09-11-2003 04:02 PM
export CC=/usr/bin/gcc-3.2 - switch gcc version? ferreter Linux - Software 1 08-20-2003 12:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration