《算法笔记》codeup_100000572_B

解答:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct student {
    int num;
    char name[20];
    char sex;
    int age;
};

int main() {
	int n;
	scanf("%d", &n);
	getchar();
	
	student* student_array = (student*)malloc(sizeof(student));  //动态构造结构体数组 
	
	int num;
	char name[20];
	char sex;
	int age;
	for(int i=0; i<=n-1; i++) {
		char s[30];
		gets(s);
		sscanf(s, "%d %s %c %d", &num, name, &sex, &age);
		
		(*(student_array+i)).num = num;                 //.的优先级比*高 
		strcpy((*(student_array+i)).name, name);
		(*(student_array+i)).sex = sex;
		(*(student_array+i)).age = age;
		
		printf("%d %s %c %d\n", (*(student_array+i)).num, (*(student_array+i)).name, (*(student_array+i)).sex, (*(student_array+i)).age);
	}
	return 0;
} 

总结:

  1. .的优先级比*高
发布了36 篇原创文章 · 获赞 3 · 访问量 1243

猜你喜欢

转载自blog.csdn.net/Zen_Ivan/article/details/105340992