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

Acceptable file format is C source file, not a text file, archive file, word doc

ID: 3807301 • Letter: A

Question

Acceptable file format is C source file, not a text file, archive file, word document or executable file. Check your program carefully before submission. Treat data differs from the sample input will be used in the grading. Make sure your program work properly for all possible cases. The grading result for this project is pass or fall For the students who pass the test, their quizzes with the lowest score in Quiz 1-5 will be dropped. Your program needs to compress a text file. The file text.txt contains the text to be compressed and thus 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 law cue and only one corresponding code in the file alpha.txt. Your 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. The content of text.txt is a. 00 b 01 c 10 d 11 The content of alpha.txt is 00 01 10 11 The content of out.txt is 5

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 path 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();
}