如何將字符串修剪成N個字符的碎片,然後將它們作爲字符串數組傳遞給函數?如何修剪並傳遞一個字符串數組到一個函數中?
這在我的程序的一部分,轉換二進制< - >十六進制。
我試着用字符串做同樣的事情,但沒有奏效。
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <String.h>
#define MAXDIGITS 8 // 8bits
int main()
{
int y;
printf("Binary-Hex convertor\n");
printf("Enter the Binary value : ");
scanf("%d", &y);
int i = MAXDIGITS - 1;
int array[MAXDIGITS];
while(y > 0)
{
array[i--] = y % 10;
y /= 10;
}
printf("%s", "-----------------\n");
printf("%s", "HEX:");
int x = array[0];
int x1 = array[1];
int x2 = array[2];
int x3 = array[3];
int x4 = array[4];
int x5 = array[5];
int x6 = array[6];
int x7 = array[7];
char buffer[50];
char buffer2[50];
char buffer3[50];
}
猜猜這是功課... – BlackBear
太聰明瞭!這不是作業。即使這是作業,爲什麼你不會與其他人分享知識? – Faisal
你能告訴我們你試過了什麼嗎? –