简单模拟题,主要是库函数的使用。fets(s, maxn, stdin);它使用时是一行一行的读入,且读取最大的字符数为maxn-1;最后补'\0',一旦遇到回车符'\n‘读取工作就会停止。这'\n'是该数组最后一个有效字符,再往后就是'\0'了。

CODE:

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
using namespace std;

const int maxn = 1001;
char s[maxn];

int main()
{
    while(fgets(s, maxn, stdin))          //fgets(s, maxn, stdin)的使用
    {
        int l = strlen(s);
        for(int i = 0 ; i < l; i++)
        {
            if(isalpha(s[i]))            //判断是否是字符
            {
                s[i] = tolower(s[i]);    //与toupper(buf[i])相对
            }
        }
        printf("%s", s);
    }
    return 0;

} 

posted on 2012-07-20 09:19  有间博客  阅读(180)  评论(0编辑  收藏  举报