C 这个程序应该画一座房子。但是这些函数赢了';行不通

C 这个程序应该画一座房子。但是这些函数赢了';行不通,c,cygwin,C,Cygwin,我正试图用C语言编写这个程序,用星星、破折号或圆点来画房子。它会问用户一组问题(大房子还是小房子),(使用什么字符?)(有多少扇窗户?),然后它应该画房子。我还没有为无效响应添加任何代码,因为我想先检查它是否适用于有效响应,但它没有。在第三个问题之后,Cygwin说“分段故障(堆芯倾倒)”。有人能告诉我是什么问题吗 #include <stdio.h> #include <math.h> #define house 1 char qbs; // for quit big

我正试图用C语言编写这个程序,用星星、破折号或圆点来画房子。它会问用户一组问题(大房子还是小房子),(使用什么字符?)(有多少扇窗户?),然后它应该画房子。我还没有为无效响应添加任何代码,因为我想先检查它是否适用于有效响应,但它没有。在第三个问题之后,Cygwin说“分段故障(堆芯倾倒)”。有人能告诉我是什么问题吗

#include <stdio.h>
#include <math.h>
#define house 1

char qbs; // for quit big small
char dsd; // for dash star dot
int now; // number of windows
int i, f; // random variables for for loops


main()
{
while(house) {
printf("Do you want a big or small house? (Q: quit, B: big house, S: small house)\n");
scanf("%s", &qbs);
switch(qbs){
    case 'B': 
    case 'b': 
    case 's':
    case 'S': break;
    default : printf("%s is not a valid choice. Please try again.\n", qbs);
              continue;
    }

printf("Which characters do you want for drawing? (DASH(-), STAR(*), or DOT(.))\n");
scanf("%s", &dsd);
printf("Using %c to draw the house.\n", dsd);

printf("How many windows do you want in the house? (0 through 4 for big houses and 0 through 2 for small houses.)\n");
scanf("%d", &now);

switch(dsd){
        case '-': dsd='-';
                  break;

        case '*': dsd='*';
                  break;

        case '.': dsd='.';
                  break;
        }
printf("%c %c %d", qbs, dsd, now);

switch(qbs){
        case 'Q':
        case 'q': printf("QUITTING THE PROGRAM.\n"); break;

        case 'B':
        case 'b': printf("         "); // this line and the next 7 lines draw the BIG roof 
                  for(i=0; i<=42; i++) {printf("%s", dsd);}
                  printf("\n      ");
                  for(i=0; i<=48; i++) {printf("%s", dsd);}
                  printf("\n   ");
                  for(i=0; i<=56; i++) {printf("%s", dsd);}
                  printf("\n");
                  for(i=0; i<=62; i++) {printf("%s", dsd);}
                 switch(now) { 
                    case '0':
                        for(f=0; i<=15; f++) { // the vertical expansion
                            for(i=0; i<=62; i++) {printf("%s", dsd); printf("\n");} // the horizontal expansion
                        }
                        break;

                    case '1':
                        for(i=0; i<=62; i++) {printf("%s", dsd); printf("\n");} // first line with no windows
                        for(f=0; f<=13; f++) { 
                            for(i=0; i<=28; i++) { printf("%s", dsd); } // left side of window
                            for(i=0; i<=6; i++) { printf(" "); } // window
                            for(i=0; i<=28; i++) { printf("%s"); } // right side of window
                        }
                        for(f=0; f<=2; f++) { for(i=0; i<=62; i++) {printf("%s", dsd);}} // bottom two lines with no windows
                        break;

                    case '2': 
                        for(i=0; i<=62; i++) {printf("%s", dsd); printf("\n");} // first line with no windows
                        for(f=0; f<=13; f++) {
                            for(i=0; i<=21; i++) { printf("%s", dsd); } // left side
                            for(i=0; i<=7; i++) {printf(" ");} // first window
                            for(i=0; i<=6; i++) {printf("%s", dsd);} // space between windows
                            for(i=0; i<=7; i++) {printf(" ");} // second window
                            for(i=0; i<=21; i++) { printf("%s", dsd); } // right side
                        }
                        for(f=0; f<=2; f++) { for(i=0; i<=62; i++) {printf("%s", dsd);}} // bottom two lines with no windows
                        break;

                    case '3': 
                        for(i=0; i<=62; i++) {printf("%s", dsd); printf("\n");} // first line with no windows
                        for(f=0; f<=13; f++) {
                            for(i=0; i<=11; i++) { printf("%s", dsd);} // left side
                            for(i=0; i<=6; i++) {printf(" "); } // first window
                            for(i=0; i<=11; i++) { printf("%s", dsd);} // space between window 1 and 2
                            for(i=0; i<=6; i++) {printf(" "); } // second window
                            for(i=0; i<=11; i++) { printf("%s", dsd);} // space between window 2 and 3
                            for(i=0; i<=6; i++) {printf(" "); } // third window
                            for(i=0; i<=11; i++) { printf("%s", dsd);} // right side
                        }
                        for(f=0; f<=2; f++) { for(i=0; i<=62; i++) {printf("%s", dsd);}} // bottom two lines with no windows
                        break;

                    case '4': 
                        for(i=0; i<=62; i++) {printf("%s", dsd); printf("\n");} // first line with no windows
                        for(f=0; f<=13; f++) {
                            for(i=0; i<=6; i++) {printf("%s", dsd);} // left side
                            for(i=0; i<=8; i++) {printf(" ");} // first window
                            for(i=0; i<=6; i++) {printf("%s", dsd);} // space between win1 and win2
                            for(i=0; i<=8; i++) {printf(" ");} // second window
                            for(i=0; i<=6; i++) {printf("%s", dsd);} // space between win2 and win3
                            for(i=0; i<=8; i++) {printf(" ");} // third window
                            for(i=0; i<=6; i++) {printf("%s", dsd);} // space between win3 and win4
                            for(i=0; i<=8; i++) {printf(" ");} // fourth window
                            for(i=0; i<=6; i++) {printf("%s", dsd);} // right side
                        }
                        for(f=0; f<=2; f++) { for(i=0; i<=62; i++) {printf("%s", dsd);}} // bottom two lines with no windows


        case 'S':
        case 's': printf("         "); // this line and the next 7 lines draw the SMALL roof
                  for(i=0; i<=12; i++) {printf("%s", dsd);}
                  printf("\n      ");
                  for(i=0; i<=18; i++) {printf("%s", dsd);}
                  printf("\n   ");
                  for(i=0; i<=24; i++) {printf("%s", dsd);}
                  printf("\n");
                  for(i=0; i<=30; i++) {printf("%s", dsd);}
                  switch(now) { 
                    case '0':
                        for(f=0; i<=6; f++) { // the vertical expansion
                        for(i=0; i<=30; i++) {printf("%s", dsd); printf("\n");} // the horizontal expansion
                        }
                        break;

                    case '1':
                        for(f=0; f<=5; f++) { 
                        for(i=0; i<=12; i++) { printf("%s", dsd); } // left side of window
                        for(i=0; i<=6; i++) { printf(" "); } // window
                        for(i=0; i<=12; i++) { printf("%s"); } // right side of window
                        }
                    for(f=0; f<=1; f++) { for(i=0; i<=30; i++) {printf("%s", dsd);}} // bottom line with no windows
                    break;

                    case '2': 
                        for(f=0; f<=5; f++) {
                            for(i=0; i<=6; i++) { printf("%s", dsd); } // left side
                            for(i=0; i<=6; i++) {printf(" ");} // first window
                            for(i=0; i<=6; i++) {printf("%s", dsd);} // space between windows
                            for(i=0; i<=6; i++) {printf(" ");} // second window
                            for(i=0; i<=6; i++) { printf("%s", dsd); } // right side
                        }
                    for(f=0; f<=1; f++) { for(i=0; i<=62; i++) {printf("%s", dsd);}} // bottom line with no windows
                    break;
                  printf("Small house with %d windows\n", now);
                  break;
}
}
}
}
#包括
#包括
#定义房屋1
字符qbs;//为了放弃大的小的
char dsd;//对于短划线星点
int now;//窗口数
int i,f;//循环的随机变量
main()
{
当(家){
printf(“你想要大房子还是小房子?(Q:退出,B:大房子,S:小房子)\n”);
scanf(“%s”和&qbs);
开关(qbs){
案例“B”:
案例“b”:
案例s:
案例:断裂;
默认值:printf(“%s”不是有效选项。请重试。\n“,qbs);
继续;
}
printf(“绘图时需要哪些字符?(短划线(-)、星形(*)或点()\n”);
scanf(“%s”和&dsd);
printf(“使用%c绘制房屋。\n”,dsd);
printf(“您希望房子有多少扇窗户?(0到4扇用于大房子,0到2扇用于小房子。)\n”);
scanf(“%d”&现在);
交换机(dsd){
案例'-':dsd='-';
打破
案例'*':dsd='*';
打破
案例“.”:dsd=”;
打破
}
printf(“%c%c%d”,qbs,dsd,现在);
开关(qbs){
案例‘Q’:
案例“q”:printf(“退出程序”。\n”);中断;
案例“B”:
案例“b”:printf(“”;//这条线和接下来的7条线绘制了大屋顶

对于整个代码中的(i=0;i,请尝试替换

printf("%s", dsd)

对scanf执行同样的操作。您需要的是字符,而不是字符串


无论如何,这很有趣,一天前有人想画同一个房子,这是你学习的练习吗?^ ^

非常混乱的代码。但是,你试过使用调试器吗?我用cygwin作为终端,用gcc作为编译器来检查错误,如果你是这个意思的话:/它编译得很好,所以没有需要输入的错误很难调试。构造一个最小的示例,最好没有菜单。例如,从画房子开始,看看你是否仍然有分段错误。这段代码中有几个明显的错误,你需要将其简化为“它编译得很好,所以没有错误”是我一直最喜欢的编程短语之一。不是在他的最后一次切换中,而是在所有地方!OP将%s与%c:混淆了。)
printf("%c", dsd)