C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 4th, 2003, 10:16 PM
xdrunkcowx xdrunkcowx is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 5 xdrunkcowx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Array with functions

hello i put this code in the compiler (Dev-C++ 4.0):

PHP Code:
#include <iostream>
using namespace std;
int main()
{
    
int i;
    
int x;
    
int a;
    
char square[25];
    
square[0] = 'a';
    
square[1] = 'b';
    
square[2] = 'c';
    
square[3] = 'd';
    
square[4] = 'e';
    
square[5] = 'f';
    
square[6] = 'g';
    
square[7] = 'h';
    
square[8] = 'i';
    
square[9] = 'j';
    
square[10] = 'k';
    
square[11] = 'l';
    
square[12] = 'm';
    
square[13] = 'n';
    
square[14] = 'o';
    
square[15] = 'p';
    
square[16] = 'q';
    
square[17] = 'r';
    
square[18] = 's';
    
square[19] = 't';
    
square[20] = 'u';
    
square[21] = 'v';
    
square[22] = 'w';
    
square[23] = 'x';
    
square[24] = 'y';
    
square[25] = 'z';
    
void read () {
    for (
i=0i<=25i++){
    
cout<<square[i];
    }
    }
    for (
a=0a<=25a++){
    for (
x=0x<=ax++){
    
read();
    }
    
cout<<"\n";
    }


and i get a **** load of errors like:
35 test22.cpp
parse error before `{'
36 test22.cpp
parse error before `)'


then i just get a lot of sntax errors like
40 test22.cpp
syntax error before `<='


if i take out the read fuction and the calling of the read function it all compiles fine.. could someone please help me figure out what im doing rong.. thanks,
Jordan

Reply With Quote
  #2  
Old June 4th, 2003, 11:10 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is online now
Banned ;)
Click here for more information.
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,717 Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Days 12 h 22 m 42 sec
Reputation Power: 1179
You can't declare one function within another in C. That's the problem. You'd have to declare read() outside main(). Since read() accesses an array, you can either
(a) declare the array as a global
(b) modify the read() function to accept an array pointer as a parameter.

Hope this helps

Reply With Quote
  #3  
Old June 5th, 2003, 11:04 AM
Analyser's Avatar
Analyser Analyser is offline
*bounce*
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2002
Location: Delft, The Netherlands
Posts: 510 Analyser User rank is Corporal (100 - 500 Reputation Level)Analyser User rank is Corporal (100 - 500 Reputation Level)Analyser User rank is Corporal (100 - 500 Reputation Level)Analyser User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 20 h 51 m 20 sec
Reputation Power: 9
Send a message via ICQ to Analyser
On a different note, square should actually be defined as char square[26], instead of char square[25].
__________________
"A poor programmer is he who blames his tools."
http://analyser.oli.tudelft.nl/

Reply With Quote
  #4  
Old June 6th, 2003, 01:39 AM
TechNoFear TechNoFear is offline
Offensive Member
Dev Shed Novice (500 - 999 posts)
 
Join Date: Oct 2002
Location: in the perfect world
Posts: 594 TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 14 h 6 m 15 sec
Reputation Power: 22
char sSquare[27];//extra space for the '\0'

sprintf(sSquare,"abcde...........xyz");
__________________
The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

Frank Zappa

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Array with functions


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT