hi,
this is something i keep running into.
for example, in the following example of strtok, i'm splitting a given string on a space(" ") delimiter:
#include<stdio.h>
#include<string.h>
int main()
{
char str[]="1234563 34 7898";
char delim[]=" ";
char* result=NULL;
char new[15][3];
int i=0;
int j=0;
bzero(new, sizeof new);
result=strtok(str,delim);
i=0;
while( result != NULL ) {
printf( "result is \"%s\"\n", result );
strcpy(new[i],result);
i++;
printf("new[%d]=%s\n",i,new[i]);
result = strtok( NULL, delim );
}
return 0;
}
while result prints the output correctly, the contents of new[] are printed truncated.
happens a lot of times and is probably a very important concept i'm missing out on. whats the way out?
Thanks!