C programming. Please add helpful and/or relevant comments. Relevant Programming
ID: 3802604 • Letter: C
Question
C programming. Please add helpful and/or relevant comments.
Relevant Programming Concepts: String in C The data compression algorithm RLE (Run Length Encoding) is based on the fact that a symbol within the data stream may be repeated many times in a row. This repetitive sequence can be replaced by a) An integer that declares the number of the repetitions b) The symbol (character) itself Write a C program that accepts a string of up to 100 characters and uses the RLE algorithm to compress it. Do NOT compress digits and Do NOT compress characters that appear once. Sample code execution 1: Red entered by a user Enter data stream: fffmmmm123bjjjjjjjjjjxttta789 Compressed stream: 3f4m123b10jx3ta789 Sample code execution 2: Red entered by a user Enter data stream: a5bggggggrrrrruuuklm Compressed stream: a5b6g5r3uklmExplanation / Answer
#include< stdio.h>
#include< conio.h>
#include< string.h>
void main()
{
int i,j,k,count[100]={0};
char str[100];
clrscr();
printf("Enter data stream: ");
scanf("%s",str);
printf(" Compressed stream is: ");
k= strlen(str);
for(i=0;i<k;i*=1)
{
j = 0;
count[i] = 1;
do
{
j++;
if(str[i+j] == str[i])
count[i]++;
}while(str[i+j]==str[i]);
if(count[i]==1)
printf("%c",str[i++]);
else
{
printf("%d%c",count[i],str[i]);
i += count[i];
}
}
getch();
}
This program will not compress digits because it accepts only character streams.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.