| | |
Segmentation Fault when run in Linux but perfect compilation and execution in Windows
![]() |
•
•
Join Date: Nov 2006
Posts: 1
Reputation:
Solved Threads: 0
Segmentation Fault when run in Linux but perfect compilation and execution in Windows
0
#1 Nov 13th, 2006
Hello Friends...
I've written a code for Simulating Paging algorithm using LRU...
The code is in the attached file.
Now on windows... it is executing perfectly, giving the output i desire...
but on Linux REGAL gnu compiler, it is giving me the error...
Error file is attached... as error2.jpg
SEGMENTATION FAULT
Can someone help me with this?
How to solve this problem?
I've written a code for Simulating Paging algorithm using LRU...
The code is in the attached file.
Now on windows... it is executing perfectly, giving the output i desire...
but on Linux REGAL gnu compiler, it is giving me the error...
Error file is attached... as error2.jpg
SEGMENTATION FAULT
Can someone help me with this?
How to solve this problem?
Re: Segmentation Fault when run in Linux but perfect compilation and execution in Windows
0
#2 Nov 14th, 2006
Re: Segmentation Fault when run in Linux but perfect compilation and execution in Windows
0
#3 Nov 14th, 2006
compile your program for debug then when the core file is created use debugger on it to see where the problem is.
Suggestion: your program makes no input validations. How does it know that argv[1] contains an integer between 0 and 20? what happens if I enter 500 as argv[1] ?
you can simplify the above like below. It is not necessary to specify the initialization of each element of the array because the compiler will set all unspecified initializer to 0 for you.
>> while (!feof(in))
we have said many many times on these boards that you should not rely on feof() because it does not always catch eof-of-file at the right time. Instead you should code it like this:
Where is pointer ea allocated? I see where it is declared and left unitialized, but I don't see where you allocated any memory for it. That may explain the seg fault you are getting.
why did you make this do difficult? you don't need that switch statement
Suggestion: your program makes no input validations. How does it know that argv[1] contains an integer between 0 and 20? what happens if I enter 500 as argv[1] ?
C Syntax (Toggle Plain Text)
int cstr[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // stores c-values from distance string int fstr[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // stores f-values from c-str giving probability of page faults
C Syntax (Toggle Plain Text)
int cstr[20]={0}; // stores c-values from distance string int fstr[20]={0}; // stores f-values from c-str giving probability of page faults
>> while (!feof(in))
we have said many many times on these boards that you should not rely on feof() because it does not always catch eof-of-file at the right time. Instead you should code it like this:
C Syntax (Toggle Plain Text)
while( fgets(ea, 2, in) ) { // blabla }
Where is pointer ea allocated? I see where it is declared and left unitialized, but I don't see where you allocated any memory for it. That may explain the seg fault you are getting.
C Syntax (Toggle Plain Text)
for(i=0;i<dsn;i++) { printf("%d ",diststr[i]); switch(diststr[i]) {
C Syntax (Toggle Plain Text)
for(i=0;i<dsn;i++) { printf("%d ",diststr[i]); if( diststr[i] < 20) cstr[diststr[i]]++; else cstr99++; }
Last edited by Ancient Dragon; Nov 14th, 2006 at 8:58 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Segmentation Fault while swapping strings. Runs perfect when compiled with tc complr (C)
- string input segmentation fault on linux (C++)
- @@segmentation fault@@ (C)
- Segmentation Fault (C++)
- Segmentation fault (Python)
- help on 'Segmentation Fault' (C)
- segmentation fault (C)
Other Threads in the C Forum
- Previous Thread: Calling C function from MATLAB
- Next Thread: Compiling Question
| Thread Tools | Search this Thread |
* adobe api array arrays binarysearch calculate centimeter char cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux hacking hardware highest homework i/o ide inches incrementoperators intmain() iso km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat opensource openwebfoundation pattern pdf performance pointer posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition scanf scheduling segmentationfault send shape single socketprograming socketprogramming stack standard strchr string suggestions test unix urboc user variable voidmain() whythiscodecausesegmentationfault win32api windows.h






