GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 10-Oct-2004, 22:38
melas melas is offline
New Member
 
Join Date: Oct 2004
Posts: 3
melas is on a distinguished road
Talking

problem with arrays


I have to write a program with arrays, and I don't understand it very well, if there is somebody that can help me, I'll be glad to send the code, to have it checked
  #2  
Old 11-Oct-2004, 00:03
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 890
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
Just post your code or attach your files and we'll see what we can do for you

Kind regards,
Luci
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #3  
Old 11-Oct-2004, 04:57
melas melas is offline
New Member
 
Join Date: Oct 2004
Posts: 3
melas is on a distinguished road

here is the code


there is a fatal error
Attached Files
File Type: txt Copy of program5.txt (934 Bytes, 19 views)
  #4  
Old 11-Oct-2004, 05:43
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 890
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
Quote:
Originally Posted by melas
there is a fatal error
This must be it:

CPP / C++ / C Code:
 p[n] = p[NUM_PRIMES];

Your array has a length of NUM_PRIMES (0,..., NUM_PRIMES -1). You can't access p[NUM_PRIMES]:

CPP / C++ / C Code:
int p[NUM_PRIMES] = {2, 3};

May I also say I don't really follow your logic?

CPP / C++ / C Code:
 void generatePrimes(int p[], int numToGenerate)  
{
    int i, num, n;
 
    if (isPrime(num, p, n) == 1)
       numToGenerate = num;
       p[i] = p[n];
}

What would i be here? You don't assign it a value...
Also, what is this line suppose to do? (in the same function)

CPP / C++ / C Code:
numToGenerate = num;

I see you pass NUM_PRIMES as the second argument...
Maybe you should give it a second thought, huh? :-D

Best regards,
Luci
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #5  
Old 11-Oct-2004, 10:45
melas melas is offline
New Member
 
Join Date: Oct 2004
Posts: 3
melas is on a distinguished road

problem


Luci I'm sorry I did not explain myself, here is what I'm supposed to do: (see attachment)
thanks, David
Attached Files
File Type: doc pgm5.doc (30.0 KB, 12 views)
  #6  
Old 12-Oct-2004, 04:18
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 890
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
Ok, but this doesn't change anything.... The mistake(s) I pointed out is obvious: you pass the length of your array and that causes the fatal error.
Maybe I wasn't to clear

Kind regards,
Luci
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
 
 

Recent GIDBlogToyota - 2008 August Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB 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
Knight tour (arrays help needed) dilmv C++ Forum 7 18-Oct-2004 14:31
Mother board problem mrkamran Computer Hardware Forum 2 07-Oct-2004 10:31
Mpeg2 SVCD disc problem mrnobody Computer Software Forum - Windows 0 13-Aug-2004 08:51
Another FX 5600 problem (but with details that might shed light on this) BobDaDuck Computer Hardware Forum 2 16-Apr-2004 07:53
folder problem in trees zuzupus MySQL / PHP Forum 23 26-Sep-2003 07:32

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:29.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.