zoukankan      html  css  js  c++  java
  • C语言程序举例


    C语言百例之读写字符串

    字符串大小写转换

    #include<stdio.h>
    #include<ctype.h>
    int main(int argc, char const *argv[])
    {
        char ar;
        printf("please input some char 
    ");
        do
        {  // 大小写转换
            ar=getchar();
            if(islower(ar))//是大写
                ar=toupper(ar);//转换小写
            else
                ar=tolower(ar);
            putchar(ar);
        }while(ar!='q');
        return 0;
    }
    

    –对于这个例子,主要是字符大小写转换,利用的函数为toupper()和tolower();包含在函数ctype.h当中。

    –在我们使用getchar()函数时,需要注意getchar()的原始形式中,输入先被缓冲,按入回车才返回写入到你需要的地方,这就是所谓的行缓冲输入。所以conio.h中提供了另外两个函数分别为 getche()和getch(); –

    char br =getche();//代表写入直接回显;
    getch()//不直接回显;
    

    简单的打开关闭函数

    #include<stdio.h>
    #include<stdlib.h>
    int main(int argc, char const *argv[])
    {
        FILE*fp;
        char ch,filename[10];
        printf("Please input the name of the file :
    " );
        scanf("%s",filename);
        if ((fp=fopen(filename,"r")==NULL))
        {
            printf("can't open the file 
    ");
            exit(0);
        }
        fclose(fp);
        return 0;
    }
    

    –本例简单的讲了文件的打开和关闭函数fopen();

  • 相关阅读:
    servlet生命周期总结
    两周找工作有感
    PowerBuilder中新建PBL
    oracle navicat 可视化操作进行数据的修改
    oracle for update for update nowait
    表中字段为关键字,查询字段加引号
    愿你
    oracle安装注意
    随笔
    JeeSite功能模块解读,功能介绍,功能实现
  • 原文地址:https://www.cnblogs.com/VCctor/p/5100706.html
Copyright © 2011-2022 走看看