Fedora Linux Support Community & Resources Center
  #1  
Old 9th June 2007, 09:17 AM
mediator's Avatar
mediator Offline
Registered User
 
Join Date: Dec 2006
Location: I am ubuiquitous
Posts: 133
Lightbulb Segmentation fault!

Hi the following code compiles fine and gives correcct output. But at the end it gives segmentation fault. Can anyone throw some light at it?

Code:
#include<iostream.h>

int main(int argc,char *argv[])
{
 int i=0;
 cout<<"argc : "<<argc<<endl;
 while(argv) {cout<<argv[i]<<endl; i++;}
 
 return 0;
}
Reply With Quote
  #2  
Old 9th June 2007, 09:29 AM
giulix's Avatar
giulix Offline
"Fixed" by (vague) request
 
Join Date: Oct 2005
Location: GMT+ 1
Posts: 2,950
It's the while statement. Modify to
Code:
while(i < argc)
or substitute with
Code:
for(i = 0; i < argc; i++)
What's happening is the while condition is always true and you end up pointing outside the process space in {cout<<argv[i]<<endl; i++;}

Last edited by giulix; 9th June 2007 at 09:34 AM.
Reply With Quote
  #3  
Old 9th June 2007, 09:40 AM
mediator's Avatar
mediator Offline
Registered User
 
Join Date: Dec 2006
Location: I am ubuiquitous
Posts: 133
Thanx for that. But can u please elaborate ur explanation a little more?
Reply With Quote
  #4  
Old 9th June 2007, 09:44 AM
giulix's Avatar
giulix Offline
"Fixed" by (vague) request
 
Join Date: Oct 2005
Location: GMT+ 1
Posts: 2,950
Read this and debug your program...
Reply With Quote
  #5  
Old 9th June 2007, 10:39 AM
mediator's Avatar
mediator Offline
Registered User
 
Join Date: Dec 2006
Location: I am ubuiquitous
Posts: 133
Ok, thanx!
Reply With Quote
  #6  
Old 9th June 2007, 11:10 AM
giulix's Avatar
giulix Offline
"Fixed" by (vague) request
 
Join Date: Oct 2005
Location: GMT+ 1
Posts: 2,950
What I mean is use a debugger to debug your program... where I live it's the same thing, but I guess in English it may mean different things...
Reply With Quote
  #7  
Old 29th July 2007, 12:55 PM
mediator's Avatar
mediator Offline
Registered User
 
Join Date: Dec 2006
Location: I am ubuiquitous
Posts: 133
And do u know me? How do u know that English isn't my native? Neways 'october 14' is my brother's B'Day too!
Reply With Quote
Reply

Tags
fault, segmentation

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
segmentation fault RoastP3nguin Programming & Packaging 3 17th June 2008 04:11 AM
Segmentation fault. GodL1ke Using Fedora 7 23rd October 2007 05:04 AM
NFS on FC3: Segmentation fault pnix Servers & Networking 0 18th August 2005 10:12 AM
ls Segmentation fault hksky Using Fedora 1 28th July 2005 03:09 PM
apt segmentation fault arathalion Using Fedora 1 21st November 2004 12:34 AM


Current GMT-time: 02:45 (Sunday, 19-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat