-
passing arrays
I'm having some trouble figuring out how to pass arrays. I need to write a function with 3 parameters: a,b,i. A and B are char arrays. The parameter i is an int. The function inserts the string a into b immediately after index i. Assume b is large enough to hold the added characters.
So an example of what I'm trying to do is the following...
A is "Today Wednesday"
b is "is"
i is 6
and the result of the function would be
Today is Wednesday
-
I believe you can use pointers to pass the arrays if you donot know how to do so i can look up an example of such a code for you
-
Code:
// this is the prototype
void insert_word( char line[], char word[], int pos );
// example use
int main ( ) {
char buff[100] = "Today Wednesday";
char insert[] = "is";
insert_word( buff, insert, 6 );
return 0;
}
-
you want something exact ne??? so it will be
Code:
memmove(a+i+strlen(b)-1, a+i,strlen(a)-i)
/*i'm not sure about this, i mean, i dont know if the arguments
are in the correct order for this function, i used memmove(dest,source, num)*/
memcpy(a+i,b,strlen(b)-1)
/*again used memcpy(dest,source, num)
but i'm not sure about the order of the arguments*/
-
if you want me to explain.... pm me or mail me at [email protected]