Re: Cannot return values of char variable



Ok, here it goes.

The problem is that i cannot, like in this example, return a char[]
correctly.

in this case i have do create a void function.

Although *array[] param keeps the alteration made to it i cannot do
this function with this signature:

char divide(char search_string[], char *array[], char *delimiter)

and return correctly the string.


Can you give me some tips on how i could return a string (or char
array) in this divide function?

Thank for all the help!
--------------------------------------------


void divide(char search_string[], char *array[], char *delimiter){



int loop;



array[0]=strtok(search_string,delimiter);

if(array[0]==NULL)

{

printf("No test to search.\n");

exit(0);

}



for(loop=1;loop<50;loop++)

{

array[loop]=strtok(NULL,delimiter);

if(array[loop]==NULL)

break;

}



for(loop=0;loop<50;loop++)

{

if(array[loop]==NULL)

break;



//printf("\nDivide - array[%d] = %s", loop,array[loop]);



}

}

.



Relevant Pages

  • Re: is there an alternative to strstr
    ... >> To exploit this fact, you need a different data format, a plain string is ... > Ok I have put the email ids in a sorted array. ... However you can use an array of char pointers and use ... int cmp(const void *v1, const void *v2); ...
    (comp.lang.c)
  • Re: copy a string into a 2d array of chars
    ... This split function should allocate a 2D array of chars ... >focus the program the string is not actually split. ... later) is an array of char containing the original contents of the ... The i-th pointer will contain the starting address of the ...
    (comp.lang.c)
  • Re: K&R2, exercise 5.4
    ... int strend(char*, char*); ... Now ps points to the first character of a string which is one character ... * don't want to FAKE the array call ... outer for loop checks for each element of 1st array. ...
    (comp.lang.c)
  • Re: Arrays of Strings, malloc
    ... Each string is at most 50 characters long, ... How do I actually start the array? ... an "array of pointers" and a "pointer ... Allocate space for some number of pointers to char ...
    (comp.lang.c)
  • Re: return a string
    ... > How to I do to return a string as a result of a function. ... of any array) is implicitly converted, in most contexts, to a pointer ... char array with a string literal, but I don't think that's what you ...
    (comp.lang.c)