Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem: Your C program needs to compress a text file. The file \'text.txt\' con

ID: 3810018 • Letter: P

Question

Problem:

Your C program needs to compress a text file. The file 'text.txt' contains the text to be compressed and this file contains lower case letters only. The file 'alpha.txt' contains the code for each letter.

You need to create a file called 'out.txt' to store the compressed text.

It is sure that all the letters in 'text.txt' will have one and only one corresponding code in the file 'alpha.txt'.

Your C program needs to achieve the indeed compression and could solve the “tail bit problem”. You need to submit a one-page document to introduce how these two problems are solved. To solve the “tail bit problem”, you may write some additional information into the output file.

Sample Input & Output:

The content of 'text.txt' is:

adbb

The content of 'alpha.txt' is :

a 00
b 01
c 10

d 11

The content of 'out.txt' is:

5

Note: I don't know what the "tail bit problem" is.

Explanation / Answer

#include <stdio.h>
#include <string.h>
#include <conio.h>
void main()
{
int i=0,j=0,cnt=0;
char ch, strng [32000];
FILE *f1,*f2;
f1=fopen ("J: ext.txt","r"); //specify your file paath for input
while((strng[i]=getc(f1))!=EOF)
{
printf ("%c",strng[i]);
i++;
}
getch ();
printf (" ");
f2=fopen("J:\out.txt","w"); //output file path
fclose (f2);
while(j<=i)
{
ch=strng [j];
while(ch==strng[j]&&j<=i)
{
cnt++;
j++;
}
f2=fopen ("J:\out.txt","w");
printf (" %c%d",ch,cnt);
fprintf (f2,"%c%d",ch,cnt);
fclose (f2);
cnt=0;
j++;
}
fclose (f1);
getchar ();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote