C6改大写输出
本帖最后由 我爱橙 于 2022-5-12 16:09 编辑读入一行英文文本将其中每个单词的最后一个字母改成大写,然后输出此文本行(这里的单词是指由空格隔开的字符串)
例如:若输入"I am a student."
则应输出"I aM A studenT."
#include"conio.h"
#include"stdio.h"
#include"ctype.h"
#include"string.h"
up1st(char *p)
{
/**************FOUND********/
integer k=0;
for(;*p;p++)
if(k)
{
/**************FOUND********/
if(*p='')
{
k=0;
/**************FOUND********/
*(p-1)=toupper(*(p-1);
}
}
else if(*p!='')k=1;
*(p-1)=toupper(*(p-1));
}
main()
{
char chrstr;
clrscr();
printf("\nPlease enter a string:");
gets(chrstr);
printf("\n\nBefore changing:\n%s",chrstr);
up1st(chrstr);
printf("\nAfter changing:\n%s",chrstr);
}
15 13 if(*p='') empty character constant
22 17 else if(*p!='')k=1; empty character constant
10 5 'integer' was not declared in this scope
12 8 'k' was not declared in this scope
29 9 'clrscr' was not declared in this scope
correct:
1.int k=0;
2. if(*p=='')
3.*(p-1)=toupper(*(p-1)); √
改正错误后运行:
#include"stdio.h"
#define N 10
/**************FOUND********/
int fun(int *a,int *b,int n)
{
int *c,max=*a;
for(c=a+1;c<a+n;c++)
if(*c>max)
{
max=*c;
/**************FOUND********/
*b=c-a;
}
return max;
}
int main()
{
int a,i,max,p=0;
printf("Please enter 10 integers:\n");
for(i=0;i<N;i++)
/**************FOUND********/
scanf("%d",a);
/**************FOUND********/
fun(a,&p,N);
printf("max=%d,position=%d",max,p);
}
Q:为什么输入a=0123456789,得到输出是max=1,position=6,程序功能没有得到实现啊?
页:
[1]