i want to do stuffing... this works fine for only one charecter... if u find any flaws then please tell me where it is....
Code:
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
main()
{
FILE *fp;
unsigned char *ch;
unsigned char *ch1;
int one = 0x80;
int counter = 0;
int count = 8;
int temp;
int i = 0, j = 0;
fp = fopen("./stuf", "r");
if((ch = (char *) malloc (sizeof(char))) == NULL) {
printf("allocation unsuccessful\n");
exit(1);
}
if((ch1 = (char *) malloc ( 6 * sizeof(char))) == NULL) {
printf("allocation not successful\n");
exit(1);
}
while(fread(ch, 1, 1, fp) ) {
if(*ch == '\n') {
break;
}
one = 0x80;
temp = 0;
count = 8;
i = 0;
while(one) {
temp = *ch & one;
if(temp) {
counter++;
}
else {
counter = 0;
}
temp >>= count - i - 1;
ch1[j] = ch1[j] | temp;
ch1[j] <<= 1;
one >>= 1;
i++;
if(counter == 5) {
ch1[j] <<= 1;
counter = 0;
}
}
ch1[j] >>= 1;
j++;
}
printf("%s", ch1);
}
i have taken a file in which im giving some charecters which will be input for the above pgm...