已通过测试运行,正常.有问题加我q23824056
#include
#include
main()
{
char *ptr, *ptr1;
ptr = (char *)malloc(256);
ptr1 = (char *)malloc(256);
memset(ptr, 0, sizeof(ptr));
memset(ptr1, 0, sizeof(ptr1));
printf("please input an English sentence:");
gets(ptr);
ptr1 = ptr;
*ptr -= 32;
while(*ptr!='\0')
{
if(*ptr==' '){ *(ptr+1) -= 32; }
ptr++;
}
puts(ptr1);
getch();
}
word就可以实现。格式,更改大小 写
#include
#include
main()
{
char *ptr, *ptr1;
ptr = (char *)malloc(256);
ptr1 = (char *)malloc(256);
memset(ptr, 0, sizeof(ptr));
memset(ptr1, 0, sizeof(ptr1));
printf("please input an English sentence:");
gets(ptr);
ptr1 = ptr;
*ptr -= 32;
while(*ptr!='\0')
{
if(*ptr==' '){ *(ptr+1) -= 32; }
ptr++;
}
puts(ptr1);
getch();
}
方法1限制单词长度:
#include
#include
#include
int main()
{
char c, *pstr;
char szWord[16];
while(1)
{
pstr = szWord;
while((c = getchar()) != ' ' && c != '\n' && c != EOF)
{
*pstr++ = c;
}
if(c == ' ')
*pstr++ = ' ';
*pstr = '\0';
*szWord = toupper(*szWord);
printf("%s", szWord);;
memset(szWord, 0, 16);
if(c == '\n' || c == EOF)
break;
}
}
方法二限制句子长度:
#include
#include
int main()
{
char szLine[64], *pstr = szLine;
char c;
gets(szLine);
do{
if(isalpha(*pstr))
{
*pstr = toupper(*pstr);
}
while(*pstr++ != ' ' && *pstr != '\0');
}while(*pstr != '\0');
printf("%s", szLine);
}
.