C with classes
This commit is contained in:
59
C/BasicSyntax/Structure/STRUCTURE_test1.cpp
Normal file
59
C/BasicSyntax/Structure/STRUCTURE_test1.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define length sizeof(student)
|
||||
union age1{
|
||||
int age2;
|
||||
char c;
|
||||
}a;
|
||||
struct student{
|
||||
int num;
|
||||
char name[100];
|
||||
char sex[100];
|
||||
union blast{
|
||||
int age;
|
||||
char f;
|
||||
}category;
|
||||
struct student * next;
|
||||
};
|
||||
int main(){
|
||||
int n;
|
||||
scanf("%d",&n);
|
||||
struct student temp,* p,* head,* p2;
|
||||
printf("Enter By NUMBER NAME SEX AGE\n");
|
||||
p = (struct student *)malloc(sizeof(struct student));
|
||||
//head = (struct student *)malloc(sizeof(struct student));
|
||||
//p2 = (struct student *)malloc(sizeof(struct student));
|
||||
|
||||
/*for(int i = 0; i < n; i++){
|
||||
scanf("%d%s%s%d",&a[i].num,a[i].name,a[i].sex,&a[i].age);
|
||||
a[i].next = (struct student *)&a[i];
|
||||
}
|
||||
<09><><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD>struct<63><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4>洢<EFBFBD><E6B4A2><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>
|
||||
*/
|
||||
head = p;
|
||||
int i = 1;
|
||||
while(i <= n){
|
||||
scanf("%d%s%s%d",&p->num,p->name,p->sex,&p->category.age);
|
||||
if(i == n)
|
||||
{
|
||||
p->next = NULL;
|
||||
break;
|
||||
}
|
||||
else p2 = (struct student *)malloc(sizeof(struct student));
|
||||
p->next = p2;
|
||||
p = p2;
|
||||
i++;
|
||||
}
|
||||
p = head;
|
||||
while(p!=NULL){
|
||||
printf("The age of %s is %d, he is a %s\n",p->name,p->category.age,p->sex);
|
||||
p2 = p;
|
||||
p = p->next;
|
||||
free(p2);
|
||||
}
|
||||
printf("\n");
|
||||
//free(p);
|
||||
//free(head);
|
||||
//free(p2);
|
||||
return 0;
|
||||
}
|
||||
7
C/BasicSyntax/Structure/Structure_Union.cpp
Normal file
7
C/BasicSyntax/Structure/Structure_Union.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
14
C/BasicSyntax/Structure/Union_test1.cpp
Normal file
14
C/BasicSyntax/Structure/Union_test1.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
|
||||
union category{
|
||||
int a;
|
||||
char b;
|
||||
double c;
|
||||
};
|
||||
|
||||
int main(){
|
||||
union category arse;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user