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:

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);
while( result != NULL ) {
   printf( "result is \"%s\"\n", result );
    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?

Recommended Answers

You're incrementing i in the wrong place.

Jump to Post

All 3 Replies

You're incrementing i in the wrong place.

char new[15][3];

Make it:

char new[3][15];

[15][3] Means 15 rows of 3 cols
[3][15] Means 3 rows of 15 cols

Thank you aspire and nisheeth!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.