5
I have a problem in the function below that truncates all words to have at most N characters.
For example: if the string "freedom, equality and fraternity" means the invocation of truncW(t,4)
should give "libe igua 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);
}
The output gives only : "libe"
I wonder how I do to go through the entire list and take out at most n characters of each word . What is missing in the code to allow this?
if (isspace(t[i]) > 0) /* ... */;
??? There is no impediment to theisspace()
return a negative number to indicate true.– pmg