所以我正在为 C 中的 Bit Stuffing 编写代码。我想做的是从用户那里获取输入,继续使用“%”运算符将数字除以得到每个数字。只要没有在整数范围。如果我使用 long int 类型,代码不再有效,主要是因为“n/10”不再是整数。那么我如何对 long int 类型变量进行整数除法。在 python 中“//”曾经工作出于这个目的。C中有什么类似的吗?而且我不想使用数组,因为在这种情况下,用户必须一次输入一个数字。这是我的参考代码。谢谢
#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;
}