-
A buffer is stored in memory somewhere.
Ptr is a pointer to an address that specifies a region within that buffer to copy.
And the word is a pointer to a buffer that malloc created for you.
-
ok! phewwwww. well ive taken most of that in. Must seem simple to you. But im finding it hard to work it out to be honest. Thanks for all your help
-
Sure, when you've programmed several years, it seems a piece of cake to you.
-
lol i just realised. that i could just print out the words with a simple printf("%s\n",ptr); didnt even realise i could do it that simple. lol i'll know for next time. Well bed time here in ireland night night.
-
-
FWIW, a strtok version:
Code:
char ** tokenize ( const char * split_it, const char * delim,
char ** string_ar, const unsigned long AR_LENGTH )
{
/**shouldn't assume that no one will want 'split_it' as-is later, so
**create a copy in memory:**/
char * split_me = duplicate( split_it );
char * found = NULL;
if( split_me != NULL ) {
unsigned long wordcount = 0;
for( found = strtok( split_me, delim );
found != NULL && wordcount < AR_LENGTH;
found = strtok( NULL /**more matches?**/, delim ) )
{
string_ar[wordcount] = duplicate( found );
if( string_ar[wordcount] == NULL )
return NULL; /**failure return**/
++wordcount;
}
string_ar[wordcount] = NULL; /**like argv**/
free( split_me );
/**free( found ); is not nexessary because it simply points
**to a part of the recent 'split_me', and since we copied the
**words to 'string_ar' we can safely free 'split_me'**/
}
return string_ar;
}