这是添加字母数字字符串中的数字的代码:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int total=0;
char ch;
printf("enter the string\n");
ch=getchar();
while(ch!='\0')
{
printf("I am here !!");
if (!(isalpha(ch)))
total+=(int)ch;
ch=(char)getchar();
printf("I am here !!");
}
printf("\ntotal is %d",total);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
无论我输入什么字符,它都会为每个字符提供4个"我在这里".
我试着用
while((ch=getchar())!='\0');
Run Code Online (Sandbox Code Playgroud)
但它给出了同样的问题.