forked from taohi/interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4-replaceblank.c
More file actions
41 lines (40 loc) · 742 Bytes
/
Copy path4-replaceblank.c
File metadata and controls
41 lines (40 loc) · 742 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
33
34
35
36
37
38
39
40
41
#include <stdio.h>
#define MAXLEN 1024
void replaceBlank(char *str,int length)
{
int len1=0,len2=0,space_num=0;
while(str[len1]!='\0')
{
if(str[len1]==' ')
space_num++;
len1++;
}
len2=len1+space_num*2;
if(len2>length)
return;
len1--;
len2--;
while(len1>=0)
{
if(str[len1] ==' ')
{
str[len2--]='0';
str[len2--]='2';
str[len2--]='%';
}
else
str[len2--]=str[len1];
len1--;
}
printf("%s\n",str);
}
int main()
{
char c,str[MAXLEN];
int i=0;
while((c=getchar())!=EOF && c!='\n')
str[i++]=c;
str[i]='\0';
replaceBlank(str,MAXLEN);
return 0;
}