zoukankan      html  css  js  c++  java
  • Array of pointers: 月份与数字对应 && Array of arrays

     Array of arrays:

    #include <stdio.h>
    #include <string.h>
    int main()
    {
        char tracks[][100] = {
            "will the protesters in American cities bring progress",
            " or set back ",
            "the cause they champion?",
        };
    
        for (int i = 0; i < 3; ++i)
        {
            strcpy(tracks[i], "there are plenty of good reasons for a young person to choose to go to university.");
            //修改track内容
        }
    
        for (int i = 0; i < 3; ++i)
        {
            printf("%s
    ", tracks[i]);
        }
        return 0;
    }

    Array of pointers:

    #include <stdio.h>
    int main()
    {
        //月份与数字对应, 比如:输入4,输出apr; 输入8, 输出aug...
        //定义二维字符数组,每一个方括号用来确定行,第二个用来确定列。
        //为什么第二个方括号数字是5,如果是4行不行?不行,因为“sept”已经占4个字符,字符串常量结尾需要0占一位,所有是5; 如果这里sept换成sep,则可以是months[][4];
        char months[][5] = {"jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sept", "oct", "nov", "dec"};
        puts("input your number: ");
        int i;
        scanf("%d", &i);
        printf("%s
    ", months[i-1]); //数组从0开始计数,输入数字3,需要对应数组元素2
        return 0;
    }
  • 相关阅读:
    正向代理和反向代理
    Unicode
    utf-8
    ISO 8895-1
    ProtocalBuffers学习记录
    C#基础知识
    MSBuild学习记录
    Linux学习笔记
    Jenkins学习记录
    CruiseControl.Net学习记录
  • 原文地址:https://www.cnblogs.com/profesor/p/12957601.html
Copyright © 2011-2022 走看看