I have a problem with the function below that truncates all words so that they have a maximum of N characters.
For example: if the string contains: "freedom, equality and fraternity", the invocation of truncW(t,4)
should give "libe equal and frat".
This is what I got:
void truncW (char t[], int n)
{
int j ;
for ( j = 0 ; j < n ; j++)
{
if ( isspace (t[j]) == 0 )
{ printf ("%c " , t[j]);}
}
}
void main ()
{
char t[] = "liberdade, igualdade e fraternidade";
truncW (t,4);
}
output gives only: "libe"
I would like to know how to scroll through the entire list and get at most n characters of each word . What's missing in the code to allow this?