#include<stdio.h> int main() { char a[20],b[20],

#include<stdio.h>
int main()
{
char a[20],b[20],*p1=NULL,*p2=NULL;
printf("请输入字符串:\n");
gets(a);
for(p1=a,p2=b;*p1!='\0';p1++,p2++)
if(*p1>='a'&&*p1<='z')
{
*p1=*p1-32;
*p2=*p1;
}else
*p2=*p1;
*p2='\0';
printf("放大后:");
printf("%s\n",b);
return 0;
}
帮忙看看有没有问题,谢谢。

这段代码中没有明显的编译错误或运行错误。

程序的功能是读入一个字符串,将其中小写字母转换为大写字母,并将转换后的字符串输出。

但是,有一些问题需要注意:

    使用gets()函数是不安全的,因为它不会检查输入的长度,可能会导致缓冲区溢出。可以使用fgets()或 scanf() 代替。

    在输出结果时使用了printf()函数,但是没有指定输出格式,因此可能会导致输出错误。

    程序没有对特殊字符进行处理,例如空格和标点符号。

    在这些问题修复后,程序就可以正常运行了。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2023-01-06
#include int main() { char a[20],b[20],c[20]; printf("Enter the first string

"); scanf("%s",a); printf("Enter the second string

"); scanf("%s",b); int i=0,j=0; while(a[i]!='\0') { c[i]=a[i]; i ; } while(b[j]!='\0') { c[i]=b[j]; j ; i ; } c[i]='\0'; printf("The concatenated string is %s",c); return 0; }
相似回答