Code:
void foo( char *bar, char **baz, size_t rows, size_t cols )
{
size_t x = 0, y = 0;
while( *bar )
{
baz[ y ][ x ] = *bar;
if( isspace( baz[ y ][ x ] ) || x + 1 == cols )
{
baz[ y++ ][ x ] = '\0';
while( *bar && isspace( *bar++ ) );
x=0;
}
else
{
x++;
bar++;
}
}
}
I haven't tried it, but that looks about right. If it is, you'll want to actually be able to explain in words what it's doing before you decide to use it as homework. If it's not, you being able to fix it should impress your teacher.
[edit]
This one is more fun!
Code:
#include<stdio.h>
#include<ctype.h>
void foo( char *s, char *bar, size_t rows, size_t cols )
{
size_t x = -1,y = 0;
while( s && *s )
{
bar[(y=isspace(*s)&&y+1<rows?y+1:y)*cols+(x=isspace(*s)?-
1:x+1<cols?x+1:x)]=isspace(*s)?'\0':*s;s=y<rows?s+1:NULL;
}
}
int main( void )
{
char * bar = "hello world";
char baz[ 2 ][ 10 ] = {{0}};
foo( bar, &baz[0][0], 2, 10 );
printf( "\'%s\' \'%s\'\n", baz[0], baz[1] );
return 0;
}
Probably still a good idea to be able to explain it before you turn it in though...
[/edit]
Quzah.