1
我剛剛開始使用C,並希望得到一些幫助。從C中構建字符串C
我有一個結構如下(IN功能等不要緊,我的問題):
void init_itype (uint32_t bits,mips_itype_t *itype) {
itype->in = bits;
itype->op = IN(bits,OP_L,OP_SZ);
itype->opbits = bitstostr(itype->op,OP_SZ,0);
itype->rs = IN(bits,RS_L,R_SZ);
itype->rsbits = bitstostr(itype->rs,R_SZ,0);
itype->rt = IN(bits,RT_L,R_SZ);
itype->rtbits = bitstostr(itype->rt,R_SZ,0);
itype->immediate = IN(bits,I_L,I_SZ);
itype->ibits = bitstostr(itype->immediate,I_SZ,0);
return;
}
我已經修改了結構如下:
printf("Instruction (in binary notation) is : %s%s%s%s\n",
itype->opbits = "100011",itype->rsbits,itype->rtbits,itype->ibits);
我打印的整個字符串只是爲了確保它的行爲應該是這樣。
我想知道的是我該如何將opbits,rsbits,rtbits和ibits存儲在單個數組中,以便將新的二進制模式存儲爲字符串?