我試圖在C中打印一個字符數組,但我無法打印所有內容。 我想打印: B1 B2 我 代碼:如何打印字符的二維數組的內容?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char def[3][10]; //define a multidimensional array of characters
strcpy(def[0],"b1"); //insert "b1" at first line
strcpy(def[1],"b2"); //insert "b2" at first line
printf("%s",def); //print everything?
}
上面的代碼打印只是b1
。我已經嘗試過:
printf("%s",def[0]);
printf("%s",def[1]);
但我有錯誤「無效的數組的使用未指定邊界」
你不能只是打印字符的多維數組。你想要打印什麼? – Linuxios
我試圖單獨打印每一行,但我不能。 – Dchris
@Dchris:那你爲什麼不發佈你試過的代碼? – bitmask