zoukankan      html  css  js  c++  java
  • Linux Linux程序练习六

    题目:实现一个so库文件名称为listupper.so,so文件中实现一个函数,函数名为void upper(const char *src, char *desc),
    调用update后将参数src所指向的字符串中所有字符转化为大写字母,结果放入desc字符串中。分别用C语言编写一个程序test1,
    调用libupper.so中的upper函数,用C++语言编写一个程序test2,调用libupper.so中的upper函数。

    upper.h

    #ifndef _upper
    #define _upper
    
    //兼容g++编译器
    #ifdef __cplusplus
    extern "C"
    {
    #endif
    void upper(const char * src,char *desc);
    #ifdef __cplusplus
    }
    #endif
    
    #endif

    upper.c

    /*
     根据函数签名分析,desc是调用函数分配内存
     */
    #include <stdio.h>
    void upper(const char * src,char *desc)
    {
        if(src==NULL||desc==NULL)
        {
            printf("传入参数不可以为空!
    ");
            return;
        }
        while(*src)
        {
            if(*src>96&&*src<123)
            {
                //说明该字符是小写字母
                *desc++=*src-32;
                src++;
            }else
            {
                *desc++=*src++;
            }
        }
    }

    test1.c

    #include <stdio.h>
    
    #include <unistd.h>
    
    #include "upper.h"
    
    int main(int arg,char * args[])
    {
        printf("请输入不超过100个字节大小的字符串!
    ");
        char buf[100]={0};
        char desc[100]={0};
        int num=0;
        num=read(STDIN_FILENO,buf,sizeof(buf));
        if(num==0) return 0;
        upper(buf,desc);
        printf("
    用户输入的字符串是:%s",desc);
        return 0;
    }

    运行结果

  • 相关阅读:
    VirtualBox COM对象获取失败
    layui的表单功能
    phpstudy+phpstorm配置xdebug
    wamp2.5怎么设置虚拟域名
    腾讯微博-转播到微博的简单使用
    新浪微博--分享到微博的简单使用
    CKEdiotr使用入门
    GridView删除行
    Python迭代器笔记
    Java基础之打印万年历
  • 原文地址:https://www.cnblogs.com/zhanggaofeng/p/5851101.html
Copyright © 2011-2022 走看看