首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

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

2012-02-22 
再次提问,请帮忙大侠帮我看看这体有没有最简单的写法(7行左右):Please enter text line: lord of the ring

再次提问,请帮忙
大侠帮我看看这体有没有最简单的写法(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行了。我会努力的! */

热点排行