zoukankan      html  css  js  c++  java
  • c语言 9-5

    1、

    #include <stdio.h>
    
    int str_char(char x[], int key)
    {
        int len = 0;
        while(x[len])
            len++;
        int i;
        for(i = 0; i < len; i++)
        {
            if(x[i] == key)
                return i;
        }
        if(i == len)
            return -1;
    }
    
    int main(void)
    {
        char str[128];
        printf("str: "); scanf("%s", str);
        puts("
    =================");
        printf("position: %d
    ", str_char(str, 'c'));
        return 0;
    }

    2、

    #include <stdio.h>
    
    int str_char(char x[], int key)
    {
        int len = 0;
        while(x[len])
            len++;
        int i = 0;
        while(1)
        {
            if(i == len)
                return -1;
            if(x[i] == key)
                return i;
            i++;
        }
    }
    
    int main(void)
    {
        char str[128];
        printf("str: "); scanf("%s", str);
        printf("position: %d
    ", str_char(str, 'c'));
        return 0;
    }

    3、

    #include <stdio.h>
    
    int str_char(char x[], int key)
    {
        int len = 0;
        while(1)
        {
            if(x[len] == '
    ')
                break;
            len++;
        }
        x[len] = key;
        int i = 0;
        while(1)
        {
            if(x[i] == key)
                break;
            i++;
        }
        return i < len ? i : -1;
    }
    
    int main(void)
    {
        char str[128];
        printf("str: "); scanf("%s", str);
        printf("position: %d
    ", str_char(str, 'c'));
        return 0;
    }

    4、

    #include <stdio.h>
    
    
    int str_char(char x[], int key)
    {
        int i = 0;
        while(1)
        {
            if(x[i] == key)
                return i;
            if(x[i] == '')
                return -1;
            i++;
        }
    }
    
    int main(void)
    {
        char str[128];
        printf("str: "); scanf("%s", str);
        printf("position: %d
    ", str_char(str,'c'));
        return 0;
    }

  • 相关阅读:
    OSError: cannot open resource(pillow错误处理)
    boost 库中文教程
    博客案例
    requests模块
    浅析Python中的struct模块
    面试基础知识点总结
    ant安装、环境变量配置及验证
    TestNG学习-001-基础理论知识
    selenium 常见面试题以及答案
    HTML5
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14817168.html
Copyright © 2011-2022 走看看