#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define STRING "FdfsJK32f47h5"
  //常量存储区,不能被修改
#define PRINT_ARRAY(x) if((x) != NULL) printf("%s\n", (x))
void LowToUp(char * str)
{
    while(*str != NULL)
    {
        if((*str >= 'a')&&(*str <= 'z'))
        {
            *str += 'A' - 'a';
        }
        str++;
    }
}
int GetMemory(char* p)
  //如果是以空指针传入,则内存丢失
{
    p = (char*)malloc(strlen(STRING));
    if(p == NULL) return -1;
    else return 1;
}
char * GetNumber(char * str)
{
    char ret[100];
    int i = 0;
    while(*str != NULL)
    {
        if((*str >= '0')&&(*str <= '9'))
        {
            ret[i++] = *str;
        }
        str++;
    }
    ret[i] = '\0';
    return ret;
   //返回局部变量,外部指针指向该区域时,已释放...但是内容可能保留,所以可能输出结果..
}
char * GetLetter(char * str)
{
    char ret[100];
    int i = 0;
    while(*str != NULL)
    {
        if((*str >= 'A')&&(*str <= 'Z'))
        {
            ret[i++] = *str;
        }
        str++;
    }
    ret[i] = '\0';
    return ret;
  //返回局部变量,外部指针指向该区域时,已释放...但是内容可能保留,所以可能输出结果..
}
int main()
{ //看了别人找的,发现自己还差很多 - -
    char *pAll=NULL;
    char *pNumber=NULL;
    char *pLetter=NULL;
    LowToUp(STRING);
    //1. 将串中小写字符转化成大写
    if(GetMemory(pAll) == 1)
    //内存分配
    {
        strcpy(pAll, STRING);
        pNumber = GetNumber(pAll);
  //2. 提取出所有数字
        pLetter = GetLetter(pAll);
    //3. 提取出所有字母
        if((pAll[0] >= '0')&&(pAll[0] <= '9')) PRINT_ARRAY(pNumber);
    //打印
        else PRINT_ARRAY(pLetter);
        free(pAll);
        return 1;
    }
    else
    {
        printf("No Memory can be used!\n");
        return -1;
    }
}
[[it] 本帖最后由 中学者 于 2008-6-16 13:27 编辑 [/it]]
[[it] 本帖最后由 中学者 于 2008-6-16 13:28 编辑 [/it]]