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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
07-09-2003, 08:24 AM
|
#1
|
LQ Newbie
Registered: Jul 2003
Location: Bali-Indonesia
Distribution: local
Posts: 11
Rep:
|
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.
|
|
|
07-09-2003, 09:00 AM
|
#2
|
Member
Registered: Sep 2002
Location: Tulsa, OK
Distribution: Slack, baby!
Posts: 349
Rep:
|
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.
|
|
|
07-09-2003, 10:20 AM
|
#3
|
Member
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194
Rep:
|
The gcc manual is here:
http://gcc.gnu.org/onlinedocs/
but it won't teach you C
|
|
|
07-09-2003, 11:45 AM
|
#4
|
Member
Registered: Jun 2003
Location: Oricola, Italy
Distribution: RH 9, so far
Posts: 261
Rep:
|
I like the second solution, seems to be traditional.
Qu Chen
|
|
|
07-09-2003, 06:43 PM
|
#5
|
LQ Newbie
Registered: Jul 2003
Location: Bali-Indonesia
Distribution: local
Posts: 11
Original Poster
Rep:
|
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)
|
|
|
07-09-2003, 06:54 PM
|
#6
|
LQ Newbie
Registered: Jul 2003
Location: Bali-Indonesia
Distribution: local
Posts: 11
Original Poster
Rep:
|
oh i understand now..
when i re-login, this forum can not submit my reply..
thanks @e
next i'll send it by , 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..
|
|
|
All times are GMT -5. The time now is 09:50 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|