|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 我爱橙 于 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[81];
- 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=' ') [Error] empty character constant
22 17 else if(*p!='')k=1; [Error] empty character constant
10 5 [Error] 'integer' was not declared in this scope
12 8 [Error] 'k' was not declared in this scope
29 9 [Error] '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[N],i,max,p=0;
- printf("Please enter 10 integers:\n");
- for(i=0;i<N;i++)
- /**************FOUND********/
- scanf("%d",a[i]);
- /**************FOUND********/
- fun(a,&p,N);
- printf("max=%d,position=%d",max,p);
- }
复制代码
Q:为什么输入a[10]=0123456789,得到输出是max=1,position=6,程序功能没有得到实现啊?
|
|