zoukankan      html  css  js  c++  java
  • 动态二维数组指针使用示例

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <unistd.h>
    
    struct infomation{
        char plate_num[16];
        char time_str[32];
    };
    
    #define ROWNUM 20
    #define COLUMN 5
    
    int main(void)
    {
        int i = 0;
        // 20*5
        struct infomation **p2Info = (struct infomation **)malloc(ROWNUM * sizeof(struct infomation * ));
        if(p2Info == NULL){
            printf(" %d cannot malloc mem!
    ", __LINE__);
            return -1;
        }
        for(i = 0; i < ROWNUM; i++){
            //*(p2Info + i) = (struct infomation *)malloc(sizeof(struct infomation ));
            p2Info[i] = (struct infomation *)malloc(sizeof(struct infomation ));
            if(*(p2Info + i) == NULL){
                printf(" %d cannot malloc mem!
    ", __LINE__);
                return -1;
            }
            memset(*(p2Info + i), 0x00, sizeof(struct infomation ));
    
            strcpy((*(p2Info + i))->plate_num, "hello world");
            strcpy((*(p2Info + i))->time_str, "2015-03-21");
            printf("%d:%s %s
    ", i, (*(p2Info + i))->plate_num, (*(p2Info + i))->time_str);
    
        }
    
        for(int i=0; i < ROWNUM; ++i)
            free(p2Info[i]);
        free(p2Info);
        return 0;
    }
  • 相关阅读:
    NewtonSoft.Json
    属性
    csv文件
    C#和递归算法实现删除,清空,拷贝目录
    朴素贝叶斯应用:垃圾邮件分类
    压缩图片
    numpy分布图
    鸢尾花
    numpy数组及处理:效率对比
    完整的中英文词频统计
  • 原文地址:https://www.cnblogs.com/guxuanqing/p/9194493.html
Copyright © 2011-2022 走看看