Dexter
Dexter

Reputation: 25

How to do a integer division of a long int in c?

So i am writing a code for Bit Stuffing in C. What I am trying to do is take an input from user,keep on dividing the number to get each digit using "%" operator.This works as long as the no is in the range of int. If I use long int type,the code no longer works mostly because the "n/10" is no longer an integer.So how do I do an integer division of the long int type variable.In python "//" used to work for this purpose.Anything similar in C? And I don't want to use an array because in that case the user has to input one digit at a time.Here's my code for reference.Thanks

#include <stdio.h>
int main(){
    int c,n,m,bit[200]={0,1,1,1,1,1,1,0},x=7,count=0,ch=0;

    do{
        printf("Enter No:\n");
        scanf("%d",&n);
        m=n;
        while(m>0){
            c=m%10;
            m=m/10;
            if(c==1){
                count++;
            }
            else if(c==0){
                count=0;
            }
            else if(c>1 && c<10){
                printf("Invalid  Pattern.Enter Either 1 or 0.\n");
                ch=1;
                break;
            }
            ch=0;
            x++;
            bit[x]=c;
            if(count==5){x++;bit[x]=0;count=0;}
        }

    }while(ch==1);

    x++;
    bit[x]=0;
    for(int i=0;i<=5;i++){
        x++;
        bit[x]=1;
    }
    x++;
    bit[x]=0;
    for(int i=0;i<=x;i++){
        printf("%d",bit[i]);
    }
    return 0;
}

Upvotes: 0

Views: 2166

Answers (0)

Related Questions