The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Why not a segmentation fault?? lagigliaivan High Level Programming 22 05-21-2008 08:07 AM
segmentation fault rockgal High Level Programming 8 12-05-2006 08:16 AM
segmentation fault wojtyla High Level Programming 3 02-19-2005 10:53 AM
Segmentation fault jshaulis AIX 1 06-01-2004 01:16 PM
segmentation fault omran High Level Programming 2 08-01-2003 05:19 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-19-2006
Registered User
 

Join Date: Mar 2006
Posts: 26
Stumble this Post!
Segmentation Fault

hello all,

I tried a program on an array to intialise array elements from the standard input device.it is an integer array of 5 elements.but after entering the 4th element it throws a message called "Segmentation Fault" and returns to the command prompt without asking for the 5th element.

why is it so?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-19-2006
Registered User
 

Join Date: Mar 2006
Posts: 106
Stumble this Post!
Let me guess

are you counting from 1 to 5 or from 0 to 4 ?
Reply With Quote
  #3 (permalink)  
Old 04-21-2006
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,325
Stumble this Post!
Good question. Remember that when you work with an array of size 5 in C, you have locations array[0]...array[4].
Reply With Quote
  #4 (permalink)  
Old 04-21-2006
Registered User
 

Join Date: Mar 2006
Posts: 26
Stumble this Post!
sorry guys Petty mistake

thanks for your time guys.

I had done a petty mistake in scanf.I tried to accept the input like this
for(i=0;i<5;i++)
scanf("%d", a[i]); The mistake.

I was supposed to give "&a[i]" .


thanks for your time pals.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:11 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0