• step1 . day8 C语言基础练习之指针和函数


    今天继续复习指针,还是很深奥的,两点注意事项:

    1. int型数据可以强制类型转化赋值给指针变量,然后对该地址赋值(用在裸机上);

    2.指针数组是数组,存放的是指针,数组指针是数组的指针,存放的是行指针。

    利用数组指针对输入数组进行单词数目确认的函数:

    #include <stdio.h>

    int wordcount(char *str){
    int count;
    int word = 0;
    while(*str){
    count = 0;
    while((*str>='a' && *str<='z') || (*str>='A' && *str<='Z')){
    count++;
    str++;
    }
    if(*str == ' '){
    if(count>2) word++;
    str++;
    continue;
    }
    else if(*str == '')
    {
    if(count>2) word++;
    break;
    }
    else {
    do{
    str++;

    }while(*str != ' ' && *str!= '');
    }
    }
    return word;

    }
    int main(int argc, const char *argv[])
    {
    char str[100];
    printf("please input a str:");
    scanf("%[^ ]",str);

    int ret = -1;

    ret = wordcount(str);

    printf("word in str:%d ",ret);
    return 0;
    }

    使用指针和二级指针对数组进行单词翻转的函数

    #include <stdio.h>
    #include <string.h>

    void swap(char **h,char **t){

    while(*t > *h){
    **t ^= **h;
    **h ^= **t;
    **t ^= **h;
    (*h)++;
    (*t)--;
    }
    }

    void strchange(char *str){
    char *head;
    char *tail;
    head = str;
    tail = str + strlen(str)-1;

    swap(&head,&tail);

    tail = str;
    head = str;
    char *temp;
    while(1){
    while(*tail != ' ' && *tail)
    tail++;
    temp = (--tail);
    swap(&head,&tail);
    if(*(tail+1)=='') break;
    head = temp+2;
    tail = temp+2;
    }
    }


    int main(int argc, const char *argv[])
    {
    char str[100]={0};
    printf("please input a str:");

    scanf("%[^ ]",str);

    strchange(str);

    printf("str revese:%s ",str);
    return 0;
    }

  • 相关阅读:
    利用观察者模式 进行不同页面的传值
    axios请求处理
    百度地图实现鼠标绘制图形并获取相关数据
    web前端支付功能
    各种好用插件汇总(持续更新...)
    记录iview表单校验的"坑"
    JavaScript字符串方法
    2020面试汇总
    JavaScript作用域
    JavaScript原型到原型链
  • 原文地址:https://www.cnblogs.com/huiji12321/p/11135006.html
Copyright © 2020-2023  润新知