Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I want to split a sentence so that each line has at most 10 characters, lines ca

ID: 3632911 • Letter: I

Question

I want to split a sentence so that each line has at most 10 characters,
lines can be broken only at a space, and this space does not get printed.
You can assume that all entered words are less than 10 characters long, and that the length of the entered sentence is at most 400 characters. I am stuck here can some one correct it.

#include <string.h>
int main()
{char c[11],strlen;
int p=0;
int len;

printf("Type Sentence: ");
do
{
scanf("%s",&c);
len=strlen(c);
if(p==0)
{printf("%s",c);
p+=(len+1);
}
else if(p+len+1<10)
{printf(" %s",c);
p+=len;
}
else
{printf(" %s",c);
p=len;
}
}while(c[len-1]!='.');

return 0;
}

Explanation / Answer

// changed -> '//' #include int main() {char c[11],strlen; int p=0; int len; printf("Type Sentence: "); do { scanf("%s",&c); len=strlen(c); if(p==0) {printf("%s",c); p+=(len+1); } else if(p+len
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote