0
我創建了一個int數組,其中包含scanf值。
現在我想採取這些值,並使用它們來創建一個char數組。
含義,int值表示要填充到char數組中的單元的數量; 如果intarray = 3,3 chararray索引將填充'*'或'void'。將int數組整合到char數組中
例如,如果intarray是3 4 2 1
那麼 chararray將是(void)(void)(void)****(void)(void)*
。
我在C編碼,不能使用字符串。
實施例運行:
Enter picture size:
10
Enter 10 encoded lines:
0 10 -1
10 0 -1
0 1 1 6 1 1 -1
0 2 1 4 1 2 -1
0 3 1 2 1 3 -1
0 4 2 4 -1
0 3 1 2 1 3 -1
0 2 1 4 1 2 -1
0 1 1 6 1 1 -1
10 0 -1
輸出:
+----------+
| |
|**********|
| * * |
| * * |
| * *
|
| ** |
| * * |
| * * |
| * * |
|**********|
+----------+
該畫面包含34個星號。
我迄今爲止代碼:
int main()
{
int a[10][10]={{0}};
char b[10][10]={{0}};
int line=0, columna=0, columnb=0, temp1=0, temp2=0, size, count=0;
printf("Enter picture size:\n");
scanf("%d", &size);
printf("Enter %d encoded lines:\n", size);
for (line=0; line<size; line++){
scanf(" %d", &temp1);
while (temp1!=-1){
a[line][columna]=temp1;
columna++;
scanf(" %d", &temp1);
}
columna=0;
}
printf("\n");
for (line=0; line<size; line++){
for (columna=0; columna<10; columna++){
printf("%d ", a[line][columna]);
}
printf("\n");
}
columna=0;
for (line=0; line<size; line++){
while (a[line][columna]!=-1){
a[line][columna]=temp2;
while (temp2!=0){
if (columna%2==0){
b[line][columnb]='*';
columnb++;
temp2-=1;
}
else{
b[line][columnb]=' ';
columnb++;
temp2-=1;
}
columna++;
a[line][columna]=temp2;
}
}
}
for (line=0; line<size; line++){
for (columnb=0; columnb<size; columnb++){
printf("%c", b[line][columnb]);
}
printf("\n");
}
printf("This picture contains %d asterisks", count);
return 0;
}
「創建一個int陣列SCANF值」和「不能使用任何函數」似乎是一個矛盾。請澄清並添加更多示例。 – chux
你是什麼意思填充虛無?如果你的意思是'void'作爲類型,它不能被賦予'char',如果你的意思是「void」作爲一個字符串,它也不能被分配給它。 – aurelienC
無效我的意思是說,字符數組將被提交'*'或根本沒有。 這個想法是隻用'*'創建一個圖片(如griddlers) –