LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 04-22-2005, 06:23 AM   #1
Varadharajan
LQ Newbie
 
Registered: Apr 2005
Posts: 3

Rep: Reputation: 0
Segmentation fault


hello everyone,
I have written a code to calculate some values based on i/p given.I have compiled and run the program in windows turbo C , but when i run it in linux , it gives segmentation error.Help me in rectifying this.
Varadharajan.
 
Old 04-22-2005, 06:44 AM   #2
freegianghu
Member
 
Registered: Oct 2004
Location: somewhere in the street
Distribution: Window$
Posts: 192

Rep: Reputation: 30
Re: Segmentation fault

Quote:
Originally posted by Varadharajan
hello everyone,
I have written a code to calculate some values based on i/p given.I have compiled and run the program in windows turbo C , but when i run it in linux , it gives segmentation error.Help me in rectifying this.
Varadharajan.
I share the sorrow of question
 
Old 04-22-2005, 07:33 AM   #3
Nad0xFF
Member
 
Registered: Apr 2005
Location: Russia, Saint-Petersburg
Distribution: Slackware 10
Posts: 109

Rep: Reputation: 15
may be you haven't used malloc(...) ?
(in BC it works)
 
Old 04-22-2005, 07:49 AM   #4
Marius2
Member
 
Registered: Jan 2004
Location: Munich
Distribution: SuSE 9.2, 10.2, 10.3, knoppix
Posts: 276

Rep: Reputation: 31
Re: Segmentation fault

Quote:
Originally posted by Varadharajan
hello everyone,
I have written a code to calculate some values based on i/p given.I have compiled and run the program in windows turbo C , but when i run it in linux , it gives segmentation error.Help me in rectifying this.
Varadharajan.
Hard to do on so few an information - you should at least have posted your code. However, in my own experience, problems of the sort (works on one os, segfaults on another) usually are caused by undefined variables or pointers, something like

char *szmystring;
szmystring[0]=0;
/*szmystring is undefined here, but there are typical values which undefined pointers tend to contain and which are os/compiler dependant; for example, under ms toy os it's very likely some 0xcdcdcdcd or 0xcececece (don't recall which). Hence it may segfault under one, while seeming to work on another*/
 
Old 04-22-2005, 08:36 AM   #5
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
Windows folks like to do this sort of thing sometimes:
Code:
char *foo = "hello world\n";
...
// capitalize the H in hello
foo[0] = 'H';

// or sometimes this:

// append something to hello world
char *blah;
blah = strcat(foo, "woo!\n");
Both of these are wrong because they modify the string that foo points to, which is a constant string. These examples tend to work on windows, but they won't with gcc on linux (maybe not with gcc on windows either?)

If you don't believe me on the second one, read the man page for strcat it's non-obvious that it modifies its first argument.

but anyway, the question was really vague so we're all just pontificating
 
Old 04-22-2005, 10:26 AM   #6
Hivemind
Member
 
Registered: Sep 2004
Posts: 273

Rep: Reputation: 30
The answer is on line 42 in your source code.
 
  


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
what does Segmentation Fault mean ? baronlynx Linux - Newbie 10 10-25-2009 04:32 PM
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika SUSE / openSUSE 2 12-02-2005 09:34 AM
Help !!! Segmentation fault mola Linux - Software 3 06-23-2005 11:13 AM
Segmentation fault tejas15_10 Programming 9 06-20-2005 09:12 AM
Segmentation fault santhosh_o Programming 3 10-26-2004 05:45 AM

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

All times are GMT -5. The time now is 07:29 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration