• 二维数组


    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <string.h>
    
    typedef struct _Ateacher {
    	int id;
    	char *name;
    	char **stu;
    }Teacher_t;
    
    Teacher_t *createTeacher(int n)
    {
    	int i = 0, j = 0;
    	Teacher_t *st = NULL;
    	
    	st = (Teacher_t *)malloc(n*sizeof(Teacher_t));
    	for (i = 0; i < n; i++)
    	{
    		st[i].name = (char *)malloc(100);
    		
    		st[i].stu = (char **) malloc(sizeof(char *));
    		for (j = 0; j < n; j++)
    		{
    			st[i].stu[j] = (char *)malloc(100);
    		}
    	}
    	
    	return st;
    }
    
    void printst(Teacher_t *st)
    {
    	int i = 0, j = 0;
    	
    	for( i = 0; i < 3; i++)
    	{
    		printf("Tname: %s, Tid: %d 	 ->>> stu info", st[i].name, st[i].id);
    	
    		for ( j = 0; j < 3; j ++)
    		{
    			printf("	Sname%d: %s", j, st[i].stu[j]);
    		}
    		printf("
    ");
    	}
    }
    
    int main()
    {
    	Teacher_t *st = NULL;
    	int i = 0, j = 0;
    
    	st = createTeacher(3);
    	for( i = 0; i < 3; i++)
    	{
    		st[i].id = i;
    		printf("input name [%d]: ", sizeof(st[i].name));
    		scanf("%s", st[i].name);
    		
    		printf("input stu info
    ");
    		for ( j = 0; j < 3; j ++)
    		{
    			printf("	[%d]input name%d: ",  sizeof(st[i].stu[j]), j);
    			scanf("%s", st[i].stu[j]);
    		}
    	}
    	printst(st);
    	
    	return 0;
    }
    

      

    二维指针及结构体使用

  • 相关阅读:
    Redis单机操作
    Scala
    RDD算子
    Python学习之旅(七)
    python学习之旅(六)
    python学习之旅(五)
    python学习之旅(四)
    python学习之旅(二)
    python学习之旅(三)
    Python学习之旅(一)
  • 原文地址:https://www.cnblogs.com/porkerface/p/12031584.html
Copyright © 2020-2023  润新知