I have developed a program for Bitstuffing. It scans for characters from a file, and if it encounters five 1's continuously, it will append a '0' after it and write to a new file. This concept is called Bit Stuffing. Now, I need to know how to remove that '0' in the file I wrote.
==##CODE ##==
FILE *fp1,*fp2; //Couple of File pointers
int i=0; //Counter
char c; //variable to get char from File
fp1=fopen("bit.txt","r"); //Open file in Read mode
fp2=fopen("b1.txt","w");//Open file in Write mode
while(!feof(fp1))
{
c=fgetc(fp1); //scan char by char till EOF
if(c=='1') i+=1;
else if(c=='0') i=0;
fputc(c,fp2);
if(i==5)
{
fputc('0',fp2); //append 0 after five 1s and reset i
i=0;
}
fclose(fp1);
fclose(fp2);
==## END OF CODE ##==
bit.txt content: 111111
b1.txt content: 1111101
How to remove that 0?
Help would be much appreciaited.
What is the C File Function to delete a letter say, 'A' in a File. Anything like fgetc, fputc etc?
Try this method:
1) Read b1.txt
2) Check for five 1's write the contents of b1.txt into a new file temp.txt
3) Once you have written it . delete b1.txt
4) rename temp.txt as b1.txt
Program
fp3=fopen("temp.txt","w");
rewind(fp2);
i=0;
while(!feof(fp2))
{
if (i%26lt;=5)
{
c=fgetc(fp2);
fputc(c,fp3);
if (c==1)
i++;
if(i==5)
i=0;
}
}
fclose(fp2);
fclose(fp3);
remove("b1.txt");
rename("temp.txt","b1.txt");
Reply:you are most welcome...why dont you send that program to my mail. Its ibndawood@gmail.com. Thanks in advance Happy Programming! Report It
Reply:Or else you may contact a C expert. Check websites like http://getafreelnacer.com/
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment