读书人

再次提问请帮忙,该如何解决

发布时间: 2012-02-22 19:36:55 作者: rapoo

再次提问,请帮忙
大侠帮我看看这体有没有最简单的写法(7行左右):

Please enter text line: lord of the ring
LORD OF THE RING
Please enter text line: good good
GOOD GOOD
Please enter text line: *
Have a nice day!

[解决办法]
[code=C/C++][/code]#include <stdio.h >
#include <string.h>
int main()
{
while(1)
{
char *p = new char[100];
char *q = p;
printf("Please enter text line:");
gets(p);
int a = strlen(p);
while(*p != '\0')
{
if(*p > 96 && *p < 127)
*p-=32;
if(*p == '*')
{
printf("Have a nice day!");
getchar();
return 0;
}
p++;
}
puts(q);
delete []q;
q = NULL;
p = NULL;
}
return 0;
}
我改了下不知道合用不?
[解决办法]
[code=C/C++][/code]#include <stdio.h >
#include <malloc.h>
int main()
{
while(1)
{
char *p = (char*)malloc(sizeof(char)*100);
char * q = p;
printf("Please enter text line:");
gets(p);
while(*p != '\0')
{
if(*p == '*')
{
printf("Have a nice day!");
getchar();
return 0;
}
if(*p > 96 && *p < 127)
*p -= 32;
p++;
}
puts(q);
free(q);
}
return 0;
}

[解决办法]
#include <stdio.h >
#include <string.h>
main()
{
char array[80],*p=array;
while(*p!='*'){
printf("Please enter text line:");
gets(p);
while(*p) {
if(*p>='a' && *p<='z')*p-=32;
if(*p++== '*'){
printf("Have a nice day!");
return;
}
}
p=array;
puts(p);
}
}
/*已经调试过了,没问题,不过还是超过10行了。我会努力的! */

读书人网 >C语言

热点推荐