JOIN
Get Time
forums   
Search | Watch Thread  |  My Post History  |  My Watches  |  User Settings
View: Flat (newest first)  | Threaded  | Tree
Previous Thread  |  Next Thread
Programme not getting executed | Reply
this is the question - 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
////////////////////////////////////////////////////////////////////////////////
MY CODE :
#include<iostream>
#include<stack>
#include<string.h>
using namespace std;
void print(char str[],int *start,int i)
{ for(int j= *start;j<=i;j++)
{ cout<<str[j];
}
*start=i+1;
cout><<"\n";
}
int main()
{ char str[1000];
int start=0;
stack<int>space;
cin.getline(str,1000);
int l=strlen(str);
if(l<=33)
{ puts(str);
exit(0);
}

for(int i=0;str[i]!='\0';i++)
{ if(i%33==0 && str[i]==' ')
{
print(str,&start,i);
space.push(i);
}

else if(i%33==0 && str[i] != ' ')
{ int lastspace=space.top();
if(space.empty()!=1)
{
print(str,&start,lastspace);
i=lastspace+1;}

}
else if(str[i]== ' ')
{ space.push(i);
}


}
print(str,&start,l-1);
return 0;

}
Problem is it's not showing any error while compiling but when it's not getting executed in Dev c++ 5.11. Online compilation shows that it's some segmentation error . Pls help me where i have gone wrong
RSS