![]() |
|
#1
|
|||
|
|||
problems with 2d arrays..Hi, im stuck again...
Small problem... multidimensional arrays. Can i first create a 2 dimensional array of characters like this: CPP / C++ / C Code:
and then in some other function initialize it? I tried this, but no luck... CPP / C++ / C Code:
Is there any other way?? |
|
#2
|
||||
|
||||
|
Do you know how to loop yet? A common and effective way of initializing arrays of any dimension is to use a "for loop" to go through the array setting each element to the value of your desire.
CPP / C++ / C Code:
__________________
-Aaron |
|
#3
|
||||
|
||||
|
Here is one way, but not the easy way I think:
CPP / C++ / C Code:
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds |
|
#4
|
||||
|
||||
|
Beat you
__________________
-Aaron |
|
#5
|
||||
|
||||
|
yes u did,I'm one minute late... Damn, my typing is still slow...
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds |
|
#6
|
|||
|
|||
thanx, but doesnt work..Quote:
That works if i want to fill every element with NULL characters, but i want to do something else.. first i want to create an array ,which is [7][7], and then i take a character and use a switch statement to check what character that is and then initialize the array accordingly. My code looks a bit like this: CPP / C++ / C Code:
But i dont want to initialize every 26 letters, but rather declare only one array and then have some kind of switch statement to decide how to initialize it. Can it be done? |
|
#7
|
||||
|
||||
|
If this is what you want, I could give an idea of how to do this.
first, take a piece of paper and draw a 7X7 grid and fill in the '@' so that it makes and 'a'. Now, List down all the position in the array which contains the '@'. In your prev post, the char a contains '@' in the following positions: (1,1),(1,2),(1,3),(2,4),(3,4),(4,2),(4,3),(4,4),(5 ,1),(5,4),(6,1),(6,2),(6,3),(6,4). do the same with b,c,d...z Now, put all the positions for each char in a struct or array or even a file.. chose what suits your need. CPP / C++ / C Code:
![]() __________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds |
|
#8
|
|||
|
|||
aha..That worked very well. thank you.
Now i only have one small little problem left.. im using CPP / C++ / C Code:
Its just that if the user types two strings separated by ' ' (blank space) the scanf function stores the second string as well, (or something like that), and that causes problems for me... Is it possible to remove any remaining parts of the string, i've read something about CPP / C++ / C Code:
thanx |
|
#9
|
||||
|
||||
|
Well, I use scanf and fflush but there was a thread where another member suggested that I shouldnot be using it cause it may or may not work..
so you can use the fgets ot getline function or even the >> ooperator to get input. but just how to use scanf and fflush: CPP / C++ / C Code:
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds |
|
#10
|
||||
|
||||
|
Quote:
Since all you want to do is read a string, use fgets(). It's the best you can get for string input. Are you saying the space is causing problems? Why should it cause trouble? __________________
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough. -- Pearl Williams |
Recent GIDBlog
Toyota - 2008 November Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| GeForce FX 5600 problems | Peacemaker | Computer Hardware Forum | 24 | 18-Jul-2004 06:50 |
| Chaintech Geforce 5600 FX problems | bartster74 | Computer Hardware Forum | 8 | 04-May-2004 14:16 |
| need help with passing 3 arrays into a function | tommy69 | C Programming Language | 14 | 07-Apr-2004 01:22 |
| CD Burner Problems | Joe9995 | Computer Hardware Forum | 0 | 07-Feb-2004 11:47 |
| CD Burner problems | dan_wood | Computer Hardware Forum | 3 | 27-Nov-2003 20:12 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The