0

Say I have a few arrays like this:

hi=["h","i"];
how=["h","o","w"];
are=["a","r","e"];
you=["y","o","u"];

and I want to pass these to a function and have the function print out (in this way...my function is doing similar operation, but not exactly) all of the arrays such they show.

hihowareyou

I'm thinking something like this: But, somehow pack the arrays in a struct??

void printit(char *data){
  for (char i in data; i<sizeof(data)/sizeof(data[0]);i++){
    do some print operation on data[i];
  }
}

I've tried this pseudo code in various iterations with structs with varying (although persistent) degrees of failure. As such, I feel like I'm misunderstanding how to pass collections of arrays to something to be worked on from a fundamental perspective.

testname123
  • 1,061
  • 3
  • 20
  • 43
  • 1
    Are you able to accomplish this *without* having to pass the data to a function, just having the data defined in the function doing the printing? If you can't do that, being able to pass things to a function isn't going to help that much. – Scott Hunter Mar 18 '17 at 22:55
  • 3
    You could give it a try in actual code, rather than pseudocode... from what you have here it's not even clear if you know the differences between a `char` and a string, or `char *` and array of `char`, or a string literal and a character constant... – Dmitri Mar 18 '17 at 22:56
  • something like [this](http://ideone.com/4Trj6s) ? – BLUEPIXY Mar 18 '17 at 23:11
  • @BLUEPIXY whoa momma! That's it...That's just fine, right there. What is that...maneuver?? called? I need to Google it. – testname123 Mar 18 '17 at 23:43
  • `sizeof(data)` will just give you the size of a pointer. – Kevin J. Chase Mar 19 '17 at 06:10
  • Possible duplicate of [How to pass a double array to a function in C?](http://stackoverflow.com/questions/3220833/how-to-pass-a-double-array-to-a-function-in-c) – Kevin J. Chase Mar 19 '17 at 06:29

0 Answers0