|
|
#1 |
|
Away from Computer
|
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 <_<.
__________________
|
|
|
|
|
|
#2 |
|
FFR Player
Join Date: Feb 2006
Posts: 33
|
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. |
|
|
|
|
|
#3 |
|
FFR Player
|
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 |
|
|
|
|
|
#4 |
|
FFR Player
Join Date: Feb 2005
Posts: 3,228
|
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.
__________________
|
|
|
|
|
|
#5 |
|
Away from Computer
|
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.
__________________
|
|
|
|
|
|
#6 |
|
FFR Player
Join Date: Feb 2005
Posts: 3,228
|
I win!
__________________
|
|
|
|
|
|
#7 |
|
Seen your member
Join Date: Dec 2003
Location: noitacoL
Posts: 2,873
|
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 Last edited by alainbryden; 02-25-2006 at 03:54 AM.. |
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|