c - 程序没有使用 switch 语句,而是直接关闭
问题描述
以下代码:它为我的字符值/类型命中 scanf 语句的实例所有地狱都崩溃了程序立即关闭,没有错误代码,什么也没有。我觉得我正在失去它。我似乎无法弄清楚问题可能是什么,我没有任何随机中断语句或任何应该关闭代码的东西。请帮忙
#include <stdio.h>
int main() {
char type;
int value=0;
printf("Enter Shape Choice: 1 Inverted triangle, 2 Square, 3 Slope, 4 Diamond with Marked Edges\n");
scanf_s("%d", &value);
printf("Enter Charachter to draw with:\n");
scanf_s("%c", &type);
int count = 0;
int count2 = 0;
int firstcounter = 0;
int value2 = 0;
if (value == 1) {
printf("please enter how many lines you would like:");
scanf_s("%d", &value2);
}
switch (value) {
case(1):
while (firstcounter <= value2) {
for (int i = value2; i > firstcounter; i--) {
printf("*");
}
printf("\n");
firstcounter++;
}
break;
case(2):
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
printf("%c", type);
}
printf("\n");
}
;
break;
case(3):
for (int i = 0; i < 5; i++) {
count2 = 5;
while (count2 > i) {
printf(" ");
count2--;
}
count = 0;
printf("%c", type);
while (count <= i - 1) {
printf("*");
count++;
}
printf("\n");
}
;
break;
case(4):
printf(" %c", type);
int seccount = 1;
for (int i = 0; i <= 4; i++) {
int firstcount = 1;
int thirdcount = 10;
printf("\n");
if (i < 3) {
for (int k = 3; k > i; k--) {
printf(" ");
}
printf("%c", type);
while (firstcount <= seccount) {
printf("*");
firstcount++;;
}
printf("%c", type);
seccount = seccount + 2;
}
if (i >= 3) {
for (int k = 1; k < i; k++) {
printf(" ");
}
printf("%c", type);
while (thirdcount > seccount) {
printf("*");
thirdcount--;
}
seccount = seccount + 2;
printf("%c", type);
}
}
printf("\n %c", type);
;
break;
}
}
解决方案
推荐阅读
- android - RxAndroid,如何仅订阅此响应的“数据”数组?
- dynamics-crm - Dynamics 365 CRM 门户。缺少富文本编辑器
- symfony4 - Modernizr 插件和 webpack 安可
- kubernetes - Kubernetes 中的有状态作业
- android - 可以对大数据对象使用共享首选项吗?
- html - 如何在不影响其他 div 元素位置的情况下覆盖 div
- java - 我无法使用休眠本地会话工厂对象更新特定行的“shop_table”表值?
- c# - 视频和aufio文件的实际时长
- node.js - AWS Custom Authorizer 不工作,返回请求超时
- python - 在python中使用re模块时,使用\S$匹配得到的结果会丢失字符串中的最后一个元素