#include <stdio.h> #include <string.h> #include <conio.h> typedef struct _STUDENT { int nNumber; // 学号 float fScore; // 分数 }STUDENT, *PSTUDENT; STUDENT student[10]; // 定义20个大小的数组 int main(int argc, char* argv[]) { int i; // 数组初始化为0 memset(&student, 0, sizeof(student)); // 初始化数组前半部分,学号用数组的下标表示,分数用下标+50表示 for(i = 0; i < 10; i++) { student[i].nNumber = i; student[i].fScore = (float)(i + 50.0); } // 显示数组的内容 for (i = 0; i < 10; i++) { printf("student[%d].nNumber = %d\nstudent[%d].fScore = %.1f\n\n", i, student[i].nNumber, i, student[i].fScore); } // 删除数组里面第2个元素,调整后续的存放空间。 memcpy(&student[1], &student[2], sizeof(STUDENT) * 8); // 把最后的内容清零 memset(&student[9], 0, sizeof(STUDENT)); printf("删除后的内容:\n"); // 显示数组的内容 for (i = 0; i < 10; i++) { printf("student[%d].nNumber = %d\nstudent[%d].fScore = %.1f\n\n", i, student[i].nNumber, i, student[i].fScore); } getch(); return 0; } |
|