zoukankan      html  css  js  c++  java
  • putchar与getchar

    #include <stdio.h>
    #include <stdlib.h>
    void myputs(char*p) //此处的*号是标志,标志这P是一个指针
    { if(p==NULL)
    {
    printf("需要输出的字符串为空,请重新输入");

    }
    else
    {
    while(1)
    {
    putchar(*p++); //此处的* 号是运行的意思,只有在指针的定义的时候表示的才是标志,此处也是取出内容的意思
    if(*p=='') //注意此处应当是对指针指向的指针,取出其中的内容,在进行判断,字符串最后的字符是' ';
    {

    break;
    }

    }

    }
    }
    //输入函数,函数的效果相当于gets();
    void mygets(char*p)
    { if(p==NULL) //判断内存是否合法
    {
    printf("内存是非法的");

    }
    else{ printf("请输入字符串:");
    while( *p=getchar()) //注意这样做的做法依然的可以,让while继续的循环。
    {
    //*p=getchar(); //将获取到的字符给指针变量 在进行输入的时候,应当注意首先将指针取地址。不然操作无效,给指着的复制是一样的效果。
    if(*p==' ') //判断键盘输入输入放入是不是换行字符
    {
    return ;//进行返回,结束程序
    }
    else{
    p++; //将指针地址进行偏移
    }
    }
    }
    }

    //实现数组的初始化。1.指针变量,初始化的对象 2。初始化的为什么字符 3。初始化的大小
    void mymenset(char *p ,char c, int size)
    { while(size)
    {
    *p++=c;
    size--;


    }





    }
    int main()
    { char *p2=NULL; //避免定义的指针野指针,将其指向改为空。
    p2=(char *)malloc(128); //空间的开辟
    if(p2==NULL) //判断空间的开辟是否成功
    {printf("空间开辟失败");
    exit(-1); //关闭程序。
    }
    mymenset(p2,'',128); //空间的初始化,1.表示初始化的对象 2.表示初始化成的字符 3. 表示初始化的大小memset()函数
    char *p="小明很帅!";
    //puts(p);
    //函数的调用
    mygets(p2);
    myputs(p2);
    // myputs(p);
    return 0;
    }

  • 相关阅读:
    Python2 cmp() 函数
    Python round() 函数
    Python floor() 函数
    Python ceil() 函数
    Python abs() 函数
    Python oct() 函数
    Python ord() 函数
    Python hex() 函数
    Python2 unichr() 函数
    Android--------工具类StatusBarUtil实现完美状态栏
  • 原文地址:https://www.cnblogs.com/Nic-zhang/p/14513424.html
Copyright © 2011-2022 走看看