Input
You are given a single line of text, with length at most 1000 characters. The text consists of English words. Adjacent words in the line are separated by a single space.
The second line consists of a single integer 'N' denoting the width of an output line.
Output
Print the input text in the following format:
- no line of output must be more than N characters long.
- no word can be split across two lines. If a word does not completely fit in a line, move the word to the next line.
Sample Input
O SOFT embalmer of the still midnight Shutting with careful fingers
34
Sample Output
O SOFT embalmer of the still
midnight Shutting with careful
fingers
Explanation
Each output line is at most 34 characters long. "midnight" does not fit on the first line, hence it was moved to the second line. "fingers" does not fit on the second line, hence it was moved to the third line.
#include<stdio.h>
void main()
{
int n,i,c;
char arr[1000];
scanf("%d",&n);
//input
while((c=getchar())!=EOF)
{
arr[i]=c;
i++;
}
//checking
while(i!=n)
{
printf("%c",arr[i]);
i++;
}
printf("\n");
}
my code is giving an infinite loop and is not giving the output.
sample test case which I want to pass but I am failing.
Input
Imagination is more powerful than knowledge
14
OUTPUT
Imagination is\n
more powerful\n
than \n
knowledge
can anyone please help me.