-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy path18.c
More file actions
32 lines (28 loc) · 721 Bytes
/
Copy path18.c
File metadata and controls
32 lines (28 loc) · 721 Bytes
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
// Write a C program to replace all the white spaces in a string with double white spaces.
#include <stdio.h>
int main()
{
char str[100];
printf("Enter the string: ");
scanf("%[^\n]%*c", str);
char white_space_doubled_str[200];
int i = 0, j = 0;
while (str[i] != '\0')
{
if (str[i] == ' ')
{
white_space_doubled_str[j] = ' ';
white_space_doubled_str[j+1] = ' ';
j += 2;
}
else
{
white_space_doubled_str[j] = str[i];
j++;
}
i++;
}
white_space_doubled_str[j] = '\0';
printf("The string with double white spaces is: %s\n", white_space_doubled_str);
return 0;
}