Ramos801 2022-06-05 23:52 采纳率: 85.7%
浏览 38
已结题

C语言while循环问题

#include <stdio.h>
#include <stdlib.h> // for atoi

#define SIZE 10
int length(char arr[])
{
int i=0;
while(arr[i]!='\0'){
i++;
}
return i;
}
int power(int base, int n){
int result =1;
while (n != 0){
result *= base;
--n;
}

return result;    
}

int my_atoi (char c[])
{

int i =length(c)-1;
int change =0;
int cti =0;
int count=length(c)-1;
while (i>=0){
change=c[i]-'0';

cti=cti+change*power(10,count);
count--;
i--;

}
return cti;

}
int isQuit (char arr[])
{
int i;
char x []="quit";
if (length(arr)<4||length(arr)>4){
return 0;
}
for (i=0;arr[i]!='\0';i++){
if (arr[i]==x[i])
return 1;
}

return 0;

}

int main(){
int a,b,c;

char arr [SIZE];

printf("Enter a word of positive number or 'quit': " );
scanf("%s", arr);
while( isQuit (arr)==0)
{
printf("%s\n", arr);

a = atoi(arr);
printf("atoi:    %d (%#o, %#X)\t%d\t%d\n", a,a,a, a*2, a*a);

b = my_atoi(arr);
printf("my_atoi: %d (%#o, %#X)\t%d\t%d\n", b,b,b, b*2, b*b);

break;

}

return 0;

}这个代码运行之后为什么只会运行一次,而不是第二张图片所示呀,请问如何达到第二张的效果

img

img

  • 写回答

2条回答 默认 最新

  • WaitIKnowYou 2022-06-06 00:21
    关注

    你的输入语句没写在循环里 还应该删除break

    do
    {
    scanf("%s", arr);
    printf("%s\n", arr);

    a = atoi(arr);

    printf("atoi: %d (%#o, %#X)\t%d\t%d\n", a,a,a, a2, aa);

    b = my_atoi(arr);

    printf("my_atoi: %d (%#o, %#X)\t%d\t%d\n", b,b,b, b2, bb);
    }while( isQuit (arr)==0);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 6月14日
  • 已采纳回答 6月6日
  • 创建了问题 6月5日

悬赏问题

  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了