printf("%02X:%02X:%02X:%02X", buf[0], buf[1], buf[2], buf[3]);以更通用的方式:int i;for (i = 0; i < x; i++){ if (i > 0) printf(":"); printf("%02X", buf[i]);}printf("\n");要连接到字符串,有几种方法可以执行此操作...我可能会保留一个指向字符串末尾的指针并使用sprintf。您还应该跟踪数组的大小,以确保其大小不会超过分配的空间:int i;char* buf2 = stringbuf;char* endofbuf = stringbuf + sizeof(stringbuf);for (i = 0; i < x; i++){ /* i use 5 here since we are going to add at most 3 chars, need a space for the end '\n' and need a null terminator */ if (buf2 + 5 < endofbuf) { if (i > 0) { buf2 += sprintf(buf2, ":"); } buf2 += sprintf(buf2, "%02X", buf[i]); }}buf2 += sprintf(buf2, "\n");