-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathday065.c
37 lines (32 loc) · 982 Bytes
/
day065.c
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
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void) {
char *in_string;
int char_occurance_count = 1, i;
char number_string[6][6] = {
"zero", "one", "two", "three", "four", "five"
};
printf("Enter the input string\n");
scanf("%s", in_string);
printf("RLE result is ");
for(int i=0; i<strlen(in_string); i++){
int j =i+1;
if(j < strlen(in_string)){
if(*(in_string+i) == *(in_string+j)){
char_occurance_count++;
}else{
if(isdigit(*(in_string+i)))
printf("%s%c", number_string[char_occurance_count], *(in_string+i));
else
printf("%d%c", char_occurance_count, *(in_string+i));
char_occurance_count = 1;
}
}
}
if(isdigit(*(in_string+(strlen(in_string)-1))))
printf("%s%c", number_string[char_occurance_count], *(in_string+(strlen(in_string)-1)));
else
printf("%d%c", char_occurance_count, *(in_string+(strlen(in_string)-1)));
return 0;
}