Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I want to do bit stuffing. I wrote a program for that. But before doing that I need a program read a text file consisting of alphanumeric characters, white spaces & punctuations and then convert the data into binary values using ASCII codes, in C language.
Please help me.

Here is my bit stuffing code:

C++
#include<conio.h>
#include<string.h>
void main()
{
    int a[20],b[30],i,j,k,count,n;
    clrscr();
    printf("Enter frame length:");
    scanf("%d",&n);
    printf("Enter input frame (0's & 1's only):");
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    i=0; count=1; j=0;
    while(i<n)
    {
        if(a[i]==1)
        {
            b[j]=a[i];
            for(k=i+1;a[k]==1 && k<n && count<5;k++)
            {
                j++;
                b[j]=a[k];
                count++;
                if(count==5)
                {
                    j++;
                    b[j]=0;
                }
                i=k;
            }
        }
        else
        {
            b[j]=a[i];
        }
        i++;
        j++;
    }
    printf("After stuffing the frame is:");
    for(i=0;i<j;i++)
    printf("%d",b[i]);
    getch();
}



Thanks in Advance,
Dinesh
Posted
Updated 16-Oct-14 4:31am
v2
Comments
Richard MacCutchan 16-Oct-14 10:32am    
OK, and what is your question?
Dineshbabu Uvarajulu 16-Oct-14 10:35am    
I need a C program to convert text into binary after tat I have to bit stuff using the above code.

1 solution

you can write the memory of string as binary file and you are done. Here is some tutorial stuff.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900