include stdio include stdlib include string char text 1000 int text_le

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char text[1000];
int text_length, n;
/*
* text => The array with text
* indicator => index where to put the space
*/
char needSpace(char theText[1000], int indicator)
{
int length = strlen(theText);
int i;
char newText[1000];
for(i = length - 1; i >= 0; i--)
{
if(indicator != i)
newText[i+1] = theText[i];
else
newText[i] = ' ';
}
return newText;
}
int main()
{
printf("Insert your text here>>> ");
gets(text);
text_length = strlen(text);
for(n = 0; n < text_length; n++)
{
if(text[n] == '!' || text[n] == '?')
{
if(text[n+1] != ' ')
text = needSpace(text, n+1);
}
}
//puts(text);
return 0;
}