• 动态二维数组指针使用示例


    #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;
    }
  • 相关阅读:
    Redis 持久化
    Redis 事务
    select poll和 epoll
    jdk信任证书
    Java中的锁分类
    mysql触发器同步远程服务器上数据库
    正则表达式
    mysql主从同步
    MySQL逗号分割字段的行列转换技巧
    Mysql中文排序
  • 原文地址:https://www.cnblogs.com/guxuanqing/p/9194493.html
Copyright © 2020-2023  润新知