难以理解的ASCII艺术挑战

时间:2016-03-28 05:50:07

标签: c arrays pointers ascii-art

所有

我正在处理CodinGame.com上的一些挑战,我遇到了一些挑战,要求我使用带有“#”和每个空格的行循环以ASCII形式显示一个字母。 “字母”长3个字符,高5个。例如:

Line 1 = " # "<br>
Line 2 = "# #"<br>
Line 3 = "###"<br>
Line 4 = "# #"<br>
Line 5 = "# #"<br>

以下是该程序的相关代码:

int L; // Length of ASCII art char, always 3
scanf("%d", &L); // <- CodinGame scanf's all values from case into stdin 
int H; // Height of ASCII art char, always 5
scanf("%d", &H); fgetc(stdin);
char T[257]; // <- Characters that must be turned into ASCII art
char lclcpy[1025]; // <- Copy array for me to use outside of loop.

fgets(T, 257, stdin); // <- T is drawn from case to stdin

for (int i = 0; i <= H; i++) {
    char ROW[1025]; // <- String containing the current row of "#"s and spaces 
    strncpy(lclcpy, ROW, sizeof(lclcpy)); // <- I copy the row into my local copy.
    fgets(ROW, 1025, stdin); // <- Program draws ROW into its stdin.
    fprintf(stderr, "%s", lclcpy); // <- I print out the value of ROW on this line alone to debug. CodinGame uses stderr for debugging purposes.
}

循环完成后,我最终得到了ASCII艺术中的字母,这就是我的lclcpy循环播放的内容。

我想要做的只是复制与特定字母对应的大ASCII艺术图像的片段。我能够用C ++做到这一点,因为琴弦让生活变得有价值,但是我试图用C语言撕掉我的头发。

我想我会创建一个字符指针数组,数组的每个元素都指向包含字母数据的ROW / lclcpy段。不幸的是,我没有运气试图用字符指针数组或二维字符数组做任何事情。我一直在遇到段错误和其他内存问题。我还没有熟悉指针。似乎我只能在字符串模式下思考,而我发现的任何东西都没有帮助。任何帮助是极大的赞赏。请考虑我缺乏经验。谢谢。

0 个答案:

没有答案