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+lenRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.