• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >linux shell > 用shell脚本和c语言将大写字母转成小写的代码

用shell脚本和c语言将大写字母转成小写的代码

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了c语言调用shell脚本,shell排序c语言,c语言调用shell,c语言 shell,c语言版反向shell等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

haveuppernumber()
{
    #test if the string have upper number
    str="$(echo $1 | tr '[:upper:]' '[:lower:]')"
    if [ "$str" != $1 ] ; then #get some problem
        echo "[#have upper number,and i well trun them to lower:#]"
        return 1 #have upper number
    else
        return 0 #no upper number
    fi
}

if [ $# -ne 1 ] ; then
    echo "Usage: $0 <string>" >&2
    exit 1
fi

if ! haveuppernumber $1 ; then #when if is 0 it run?
#if [ 0 ] ; then #in shell true return 0 ,false return 1
    echo $1 | tr '[:upper:]' '[:lower:]' #it can turn the UPPER number to lower
#    echo $1 | tr '[:lower:]' '[:upper:]' #it can turn the lower number to UPPER
else
    echo "[#no upper number:#]"
    echo $1
fi

exit 0
</div>

功能说明:当输入”./upper_to_lower.sh AaBbCcdd“时会先判断输入格式是否正确,然后判断字符串中是否有大写字母如果有显示"[#have upper number,and i well trun them to lower:#]"和转换成小写字母后的字符串;如果没有大写字母显示"[#no upper number:#]"和小写字符串。

然后又试着用c语言实现相同的功能,如下:

int haveuppernumber(char *p)
{
    char*q=p;

    for(;*q!='\0';q++)
    {
        if(*q>='A'&&*q<='Z')
        {
            printf("[#have upper number and i will turn them to lower #]\n");
            return 1;
        }
    }
    printf("[#no upper number#]\n");
    return 0;
}
void turntolower(char *p)
{
    for(;*p != '\0';p++)
    {
        if(*p>='A' && *p<='Z')
        {
            *p+=' ';
        }
    }
}

int main(int argc , char *argv[])
{
    char *p;
    p=argv[1];

    if(argc != 2)
    {
        printf("Usage : %s <string>\n",argv[0]);
        exit(-1);
    }
    if(haveuppernumber(p))
    {
        turntolower(p);
        printf("%s\n",argv[1]);
    }
    else
    {
        printf("%s\n",argv[1]);
    }
    return 0;
}
</div>

</div>

您可能想查找下面的文章:

  • Shell脚本实现C语言代码行数统计
  • 用shell脚本和c语言将大写字母转成小写的代码

相关文章

  • iredmail下安装脚本分析(一)---get_all.sh 文件所在目录为PKGS
  • 创建Linux系统服务的方法
  • linux下部署kodexplorer的方法
  • linux下source命令使用详解
  • 一天一个shell命令 linux文本操作系列-touch命令用法
  • 解压rpm包的linux命令及rpm命令使用简介
  • 批量修改ssh配置的expect脚本
  • bash: /usr/bin/autocrorder: /usr/bin/python^M: bad interpreter: No such file or directory
  • shell脚本结合iptables防端口扫描的实现
  • Shell根据日期、月份、星期判断年份的代码

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • linux删除无效链接文件脚本分享
    • Shell中使用scp命令实现文件上传代码
    • linux命令之find命令简单概述
    • 一键配置CentOS iptables防火墙的Shell脚本分享
    • 写出健壮Bash Shell脚本的一些技巧总结
    • Shell脚本学习指南之查找与替换介绍
    • Linux BASH多进程并行处理的方法实现
    • shell 批量压缩指定目录及子目录内图片的方法
    • linux中批量修改文件名的脚本代码
    • shell for循环与数组应用介绍

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有