Go Back   Flash Flash Revolution > General Discussion > Chit Chat
Register FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
Old 02-20-2006, 04:47 PM   #1
chickendude
Away from Computer
FFR Simfile AuthorFFR Veteran
 
chickendude's Avatar
 
Join Date: Sep 2003
Location: Massachusetts
Age: 35
Posts: 1,901
Send a message via AIM to chickendude
Default Arrays of strings >_<

Yeah,
I'm programming in C here, but anyone can help.

I don't understand how to work with an array of strings (2D array of chars).
I'm trying to send them into functions and use them, but when I compile and run the program I get this HUGE HUGE HUGE pile of crap that scrolls the window down like 25 pages.

The program itself is really simple, just a merge sort. I just don't know how you send an array of strings into a function as a parameter.

Neither, strings** or strings[][] are working. Strings** doesn't seem like it makes sense, but strings[][] seems like it should work, but it doesn't.

Someone help <_<.
__________________
chickendude is offline   Reply With Quote
Old 02-20-2006, 05:19 PM   #2
Hilary_Clinton
FFR Player
 
Join Date: Feb 2006
Posts: 33
Default RE: Arrays of strings >_<

i'm guessing you'd have to call them based on their position within the array... like x[j], where x is your array of strings and j is your loop variable working with the positions in the array...

closest thing i have is an array of integers program that i wrote last semester. It may help with the syntax of working with the array. Beyond that, I'm not completely sure what you're looking to do, so its hard to help. Also, my programming is in Java. Similar to C but not exactly the same...

Anyway, here is a program... ignore it if its completely useless:

Code:
public class Asgn7
/*
 *
 * Generates n random numbers.  Store them in an array.  Print the numbers in the array backwards.
 *
 */
 
 {
 	public static void generate(int n)
 	{
 		int[] x = new int[n];
 		int rand;
 		int index = 0;
 		int len = x.length;
 		for(int j = 1; j <= n; j++)
 		{
 			rand = (int)(10*Math.random() );
 			x[index] = rand;
 			index++;
 		}
 		for(int k = len-1; k >= 0; k--)
 		{
 			System.out.println(x[k] );
 		}
 	}
 	 		
 	public static void main(String[] boob)
 	{
 		final int z = 7;
 		generate(z);
 	}
 }
__________________
I was the REAL 42nd President.
Hilary_Clinton is offline   Reply With Quote
Old 02-20-2006, 05:32 PM   #3
Tokzic
FFR Player
 
Tokzic's Avatar
 
Join Date: May 2005
Location: TGB
Age: 36
Posts: 6,878
Send a message via AIM to Tokzic
Default RE: Arrays of strings >_<

Hilary Clinton knows her haxx.

I'd help, but I'm afraid I do not know anything exquisite outside of Pascal.
__________________

Last edited by Tokzic: Today at 11:59 PM. Reason: wait what
Tokzic is offline   Reply With Quote
Old 02-20-2006, 05:39 PM   #4
stlunatic0124
FFR Player
FFR Veteran
 
Join Date: Feb 2005
Posts: 3,228
Default RE: Arrays of strings >_<

chickendude.. arrays of strings..

char arrayname[NUMBER_OF_CELLS][MAX_LENGTH_OF_STRING];

I got an A in programming for electrical engineers last semester, which was in C.. from what I remember (even though it all left my head immediately after the final), I'm pretty sure that is correct.
__________________
stlunatic0124 is offline   Reply With Quote
Old 02-20-2006, 06:46 PM   #5
chickendude
Away from Computer
FFR Simfile AuthorFFR Veteran
 
chickendude's Avatar
 
Join Date: Sep 2003
Location: Massachusetts
Age: 35
Posts: 1,901
Send a message via AIM to chickendude
Default RE: Arrays of strings >_<

thanks, that really helped

in my program, I accidentally went out of the boundaries of my array of strings... so when I printed it I got crap data

except.... I got data that looked like this
"Family15Model4St(infinitysign)"

o_O
yeahg, so my program is on the verge of working. I basically, had to put in the parameters the size when sending into a function. I also had to make the first character of the next string null so I'd know where my array ended.
__________________
chickendude is offline   Reply With Quote
Old 02-21-2006, 12:18 AM   #6
stlunatic0124
FFR Player
FFR Veteran
 
Join Date: Feb 2005
Posts: 3,228
Default RE: Arrays of strings >_<

I win!
__________________
stlunatic0124 is offline   Reply With Quote
Old 02-25-2006, 03:51 AM   #7
alainbryden
Seen your member
FFR Simfile AuthorFFR Veteran
 
alainbryden's Avatar
 
Join Date: Dec 2003
Location: noitacoL
Posts: 2,873
Default Re: Arrays of strings >_<

Arrays of strings are very strange. You have to be extremely careful how you define them

char array[size][string_length] is not an array of strings, it is a two dimentional array of characters, and has different properties it works in some cases. If you are going to make it, you need to make sure that every 'string' you put in there ends in '/0' or functions like strcpy and strlen will fail and create errors in the array.

char* array[size] is the proper way to define an array of strings, and you need to program differently with it. I recently went through some very difficult times coming to an extensive understanding of how to deal with arrays of strings in C99. If you need some help though, and no one else seems to have expertise in C, I'm certainly the man to ask. Try to catch me on AIM.

The C and Java (minus GUI) expert,

Alain
__________________
~NEIGH

Last edited by alainbryden; 02-25-2006 at 03:54 AM..
alainbryden is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

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



All times are GMT -5. The time now is 08:26 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Copyright FlashFlashRevolution