Programming C: Posts 13 – Type of structure – struct
Content
The easiest way to access the type of structure is an example of students. A class 100 students each student include your name and student code. Enter data for the class. Hehe. You think about how to use 2 Plate: 1 array names, 1 array student code right. Right, That way no wrong ... but let's see the next request ... Thi semester finished, Please enter the scores for each student, each student included 10 subjects (Mathematics, Believe, Chemistry, Physics,...). Giờ bạn thấy sao nào… Dùng 12 Did not ... oh array, hãy dùng type of structure. With just type structure 1 Plate only.
1. Type of structure
For arrays, can save a lot of information has the same data type. But with this type of structure we can store information more different data types.
1.1 VD opening
//code by nguyenvanquan7826 #include <stdio.h> #include <stdlib.h> // khai bao struct struct sinhvien { char MSV[20]; // ma sinh vien char hoten[30]; // ho ten sinh vien double toan, tin, anh; // cac diem toan, tin, anh }; /* Hay thay tat ca fflush(stdin); thanh __fpurge(stdin) khi ban lam tren linux*/ int main() { /* khai bao 2 bien sv1, sv2 va 1 mang * CNPMK10A gom 100 sinh vien */ struct sinhvien sv1, sv2, CNPMK10A[100]; printf("Nhap du lieu cho sv1:\n"); printf("MSV: "); fflush(stdin); gets(sv1.MSV); printf("Ho ten: "); fflush(stdin); gets(sv1.hoten); printf("Diem toan, tin, anh: "); fflush(stdin); scanf("%lf %lf %lf", &sv1.toan, &sv1.tin, &sv1.anh); printf("Nhap du lieu cho sv2:\n"); printf("MSV: "); fflush(stdin); gets(sv2.MSV); printf("Ho ten: "); fflush(stdin); gets(sv2.hoten); printf("Diem toan, tin, anh: "); fflush(stdin); scanf("%lf %lf %lf", &sv2.toan, &sv2.tin, &sv2.anh); printf("\n --------- Thong tin sinh vien -----\n"); printf("%-20s %-30s %-7s %-7s %-7s\n", "MSV", "Ho ten", "Toan", "Tin", "Anh"); printf("%-20s %-30s %-7.2lf %-7.2lf %-7.2lf\n", sv1.MSV, sv1.hoten, sv1.toan, sv1.tin, sv1.anh); printf("%-20s %-30s %-7.2lf %-7.2lf %-7.2lf\n", sv2.MSV, sv2.hoten, sv2.toan, sv2.tin, sv2.anh); return 0; }
Result:
Nhap du lieu cho sv1: MSV: DTC1 Ho ten: Pham Thi Ha Diem toan, tin, anh: 9 9 8 Nhap du lieu cho sv2: MSV: DTC2 Ho ten: Nguyen Van Quan Diem toan, tin, anh: 9 9 8 --------- Thong tin sinh vien ----- MSV Ho ten Toan Tin Anh DTC1 Pham Thi Ha 9.00 9.00 8.00 DTC2 Nguyen Van Quan 9.00 9.00 8.00
At the beginning of this example, chúng ta có rất nhiều điểu phải bàn 🙂
1.2 Construction type structure, declare the variable structure
As the example above, to build 1 type of structure we follow the syntax:
struct TenKieuCauTruc { Khai báo các thành phần của kiểu; };
After then the type of structure that is very similar style 1 normal type (int, float, tank,...) and we just declare another variable is finished. However, the variable declaration should be added in the previous struct keyword: (For C does not need).
struct TenKieuCauTruc TenBienCauTruc;
In addition we're also building some kind of structure and variable declaration is structured as follows:
struct TenKieuCauTruc { Khai báo các thành phần của kiểu; } danh sách các biến thuộc kiểu cấu trúc;
Or
struct { Khai báo các thành phần của kiểu; } danh sách các biến thuộc kiểu cấu trúc ;
With this declaration, It is mandatory to declare variables in the structure as soon as there is no structure type name to our structure declared in another location.
In this section, we should mention 1 important keyword, That is typedef. This keyword is used to define 1 new data types.
typedef struct sinhvien { char MSV[20]; // ma sinh vien char hoten[30]; // ho ten sinh vien double toan, tin, anh; // cac diem toan, tin, anh } kieuSinhVien;
When we have this kieuSinhVien was 1 datatypes (as int, double, ...) and we can declare variables through its structure. In this there are a few things you need to pay attention:
- With sinhvien (type of structure is placed after the keyword struct) when declaring variables of this type struct we still have in front of it. (CEO: sinhvien SVA; -> Sai còn struct sinhvien svA; -> đúng), (attention in C is not required).
- With kieuSinhVIen when declaring variables of this type we not have the struct in front of it. (CEO: struct kieuSinhVIen all; -> sai, kieuSinhVIen all; -> đúng).
In addition we can also type declarations nested structures: Eg as in 1 students Birthday, date of birth in the day, month, Year of Birth.
struct ngaysinh { int ngay, thang, nam; } typedef struct sinhvien { char MSV[20]; // ma sinh vien char hoten[30]; // ho ten sinh vien double toan, tin, anh; // cac diem toan, tin, anh struct ngaysinh ns; } kieuSinhVien;
Or we declared within the structure:
typedef struct sinhvien { char MSV[20]; // ma sinh vien char hoten[30]; // ho ten sinh vien double toan, tin, anh; // cac diem toan, tin, anh struct ngaysinh { int ngay, thang, nam; } ns; } kieuSinhVien;
1.3 Access to components of the structure
For access to the components of the structure we use the dot (.).
TenBienCauTruc.TenThanhPhan;
As one example on the following access:
sv1.hoten; sv1.toan; // access to their name, Math scores
sv1.ns.ngay; sv1.ns.thang; // access to birth date and month of birth.
...
Once access is to the components of the structure, each component is 1 It is normal variables and assign values or enter the value to them as normal, but we still do.
In addition, if certain elements lengthy, we can avoid the long lines using keywords define.
For example instead of writing:
sv1.ns.thang; sv1.ns.nam;
We write:
#define p sv1.ns p.thang; p.nam;
1.4 Assign the variables have the same type of structure
//code by nguyenvanquan7826 #include <stdio.h> #include <stdlib.h> struct sinhvien { char MSV[20]; // ma sinh vien char hoten[30]; // ho ten sinh vien double toan, tin, anh; // cac diem toan, tin, anh }; /* Hay thay tat ca fflush(stdin); thanh __fpurge(stdin) khi ban lam tren linux*/ int main() { /* khai bao 2 bien sv1, sv2 va 1 mang * CNPMK10A gom 100 sinh vien */ struct sinhvien sv1, sv2, CNPMK10A[100]; printf("Nhap du lieu cho sv1:\n"); printf("MSV: "); fflush(stdin); gets(sv1.MSV); printf("Ho ten: "); fflush(stdin); gets(sv1.hoten); printf("Diem toan, tin, anh: "); fflush(stdin); scanf("%lf %lf %lf", &sv1.toan, &sv1.tin, &sv1.anh); sv2 = sv1; // gan gia tri cua sv1 cho sv2 printf("\n --------- Thong tin sinh vien -----\n"); printf("%-20s %-30s %-7s %-7s %-7s\n", "MSV", "Ho ten", "Toan", "Tin", "Anh"); printf("%-20s %-30s %-7.2lf %-7.2lf %-7.2lf\n", sv2.MSV, sv2.hoten, sv2.toan, sv2.tin, sv2.anh); return 0; }
After assigning SV2 = SV1, all information of the SV2 SV1 has also. In addition it is also possible to assign initial values for structure.
struct sinhvien sv1 = {"ABC", "Nguyen Van Quan", 9, 9, 8, {4, 5, 1992}};
Then we have the original data is SV1:
MSV: ABC hoten: Nguyen Van Quan toan: 9 tin: 9 anh: 8 ngày sinh: 4/5/1992.
2. The array structure
Above we have to learn the basics of structure type and a few examples of structures sinhvien. Now we learn how to perform 1 Plate 50 students 1 class structure type as above. Consider the example:
//code by nguyenvanquan7826 #include <stdio.h> #include <stdlib.h> struct sinhvien { char MSV[20]; // ma sinh vien char hoten[30]; // ho ten sinh vien double diemTB; // diem trung binh struct ngaysinh { int ngay, thang, nam; } ns; }; int main() { int n = 2, i; struct sinhvien CNPMK10A[n]; for (i = 0; i < n; i++) { #define sv CNPMK10A[i] printf("Nhap du lieu cho sinh vien thu %d:\n", i + 1); printf("MSV: "); fflush(stdin) gets(sv.MSV); printf("Ho ten: "); fflush(stdin); gets(sv.hoten); printf("Diem TB: "); fflush(stdin) scanf("%lf", &sv.diemTB); printf("Ngay sinh: "); scanf("%d/%d/%d", &sv.ns.ngay, &sv.ns.thang, &sv.ns.nam); } printf("\n --------- Thong tin sinh vien -----\n"); printf("%-20s %-30s %-7s %-10s\n", "MSV", "Ho ten", "Diem Tb", "Ngay sinh"); for (i = 0; i < n; i++) { #define sv CNPMK10A[i] printf("%-20s %-30s %-7.2lf %02d/%02d/%4d\n", sv.MSV, sv.hoten, sv.diemTB, sv.ns.ngay, sv.ns.thang, sv.ns.nam); } return 0; }
Result:
Nhap du lieu cho sinh vien thu 1: MSV: DTC1 Ho ten: Pham Thi Ha Diem TB: 9.2 Ngay sinh: 21/01/1993 Nhap du lieu cho sinh vien thu 2: MSV: DTC2 Ho ten: Nguyen Van Quan Diem TB: 9.2 Ngay sinh: 31/12/1992 --------- Thong tin sinh vien ----- MSV Ho ten Diem Tb Ngay sinh DTC1 Pham Thi Ha 9.20 21/01/1993 DTC2 Nguyen Van Quan 9.20 31/12/1992
3. Structure pointer
//code by nguyenvanquan7826 #include <stdio.h> #include <stdlib.h> struct sinhvien { char MSV[20]; // ma sinh vien char hoten[30]; // ho ten sinh vien double diemTB; // diem trung binh struct ngaysinh { int ngay, thang, nam; } ns; }; int main() { int n = 2, i; // cap phat bo nho struct sinhvien *CNPMK10A = (struct sinhvien*) malloc(n * sizeof(struct sinhvien)); for (i = 0; i < n; i++) { printf("Nhap du lieu cho sinh vien thu %d:\n", i + 1); printf("MSV: "); fflush(stdin); gets(CNPMK10A[i].MSV); printf("Ho ten: "); fflush(stdin); gets(CNPMK10A[i].hoten); printf("Diem TB: "); fflush(stdin); scanf("%lf", &(CNPMK10A+i)->diemTB); printf("Ngay sinh: "); scanf("%d/%d/%d", &(CNPMK10A+i)->ns.ngay, &(CNPMK10A+i)->ns.thang, &(CNPMK10A+i)->ns.nam); } printf("\n --------- Thong tin sinh vien -----\n"); printf("%-20s %-30s %-7s %-10s\n", "MSV", "Ho ten", "Diem Tb", "Ngay sinh"); for (i = 0; i < n; i++) { #define ns CNPMK10A[i].ns printf("%-20s %-30s %-7.2lf %02d/%02d/%4d\n", CNPMK10A[i].MSV, (*(CNPMK10A+i)).hoten, (CNPMK10A+i)->diemTB, ns.ngay, ns.thang, ns.nam); } return 0; }
Access the structural components
In order to get the data access components pointer structures have 3 following:
- How to 1: CNPMK10A[in].diemTB;
- How to 2: (*(CNPMK10A i)).diemTB;
- How to 3: (CNPMK10A i) ->diemTB;
Both 3 methods will have access to DTB.
To get the address we have 2 from:
- How to 1: &CNPMK10A[in].DTB;
- How to 2: &(CNPMK10A i)->diemTB
anh ơi cho em hỏi là ở đây khi mình cấp phát động để nhập vào dữ liệu cho sinh viên, khi kết thúc trương trình này không giải phóng bộ nhớ động đã cấp phát ra ạ?
Ukm đúng rồi, cái này mình quen thói quên mất, chứ đúng ra là cần phải thêm vào đó.
cảm ơn các bài của anh rất hữu ích cho sinh viên nhập môn như em ạ 😀
ngồi hóng anh làm giải phóng bộ nhớ cho bài 11++ ạ 😀
Giải phóng bộ nhớ bạn chỉ cần free các biến con trỏ sau khi dùng là xong.
yes. em biết cách giải phóng bộ nhớ cấp phát cái này rồi ạ 😀
A ơi cho e hỏi muốn thêm 1 sinh viên vào thì phải lsao ạ
Bên trên có rồi mà.
a cho em hỏi #define ns CNPMK10A[in].ns có ý nghĩa gì ạ?
Bạn xem lại bên trên nhé. I said it means putting a variable ns for shortened for NPMK10A[in].ns
yes! thank you!
A Quân ơi cho em hỏi!!!
printf(“Nhap du lieu cho sv1:\n”);
printf(“MSV: “); fflush(stdin);
gets(sv1.MSV);
printf(“Ho ten: “); fflush(stdin); //fflush(stdin) What is sir???
gets(sv1.hoten); //gets(sv1.hoten) What is sir??nó có giống scanf(“%with” ,sv1.hoten);?
printf(“Diem toan, believe, you: “); fflush(stdin);
scanf(“%lf %lf %lf”, &sv1.toan, &sv1.tin, &sv1.anh); //%lf là gì ạ??
fflush và gets đọc mục 4 and 5 ở bài này nhé: https://cachhoc.net/2014/12/04/lap-trinh-c-bai-2-kieu-du-lieu-va-nhap-xuat-trong-c/#4_Nhap_chuoi_trong_C
lf là ký hiệu định dạng kiểu double.
thank anh trai !!!đã hiểu
let me ask this as how to find information in the list of students with student ID is X if
have. Show information the students born in December 3, brothers and sisters, pondering not out :((
Recommended: Write a program to 1 n list of students. Each student is 1
structure include: Full name, sex, place of birth, birthday (was 1 structure consisting days,
month and year), MSSV, code group. Displays information about the students entered the
Screen. Look for the list on information about students with student ID is X if
have. Show information the students born in December 3
You compare strings with strcmp function is called X with which
darling do not understand this place :”%-20s %-30s %-7s %-10s”. how many -20,-30 what's driving ạ?
reserved 20.30.7.10 space for displaying the corresponding value and negative is left flat
Waiter, in VD assigned 2 SV turn on, whether it is necessary to assign each of the variables is not it? For the school to bring a string containing special assignment as strcpy(,)
No need here, SV1 SV2 is kept = any value in SV1 SV2 given to all.
dấu trừ chỗ %-20f là gì ạ
Cái %20f là để 20 spaces for the display of numbers. So there will be a space in front of the output values. Then as we need to. If the minus sign, then we left it base.
he article basic java or not . Kids up to the reference DC ko sir
New Kids hoc only basic java- should not know much, sir
Of, This is a do not write down, only 2 all Object Oriented severance
https://www.cachhoc.net/category/lap-trinh/lap-trinh-huong-doi-tuong/
printf(” %-20s% -30s% -10s% -7s n”,”MSV”,”threats”,”birthday”,”GPA”);
printf(“%-20s %-30s %-7.2lf d/d/Mn”, sv.MSV, sv.hoten, sv.diemTB, sv.ns.ngay, sv.ns.thang, sv.ns.nam);
numbers% -20s …. What thoughts have you. so when I changed back to
printf(“%-20s% -30s% -10s% -8s”,”MSSV”,”HO TEN”,”BIRTHDAY”,”DIEMTB”);
printf(“%-20s %-30s %d/%d/%d %-8.2f”,sv[in].msv,sv[in].ht,sv[in].ns.ngay,sv[in].ns.thang,sv[in].ns.nam,sv[in].tb);
it prints out the results compared with student ID drift,THREATS,BIRTHDAY,DIEMTB
%20s is available 20 the space to print the string but it will be necessary to look bad, Using% -20s will thus help your left flat.
you ,how I can soup to give student ID,threats,birthday,diemtb, and the results show their corresponding may jointly located on 1 post ( not skewed column)…. in this article is no place he scored -30s% -20s% %-10 %-7 vv.the why I have to write so. which is not %-30 %-30 %-30 His lun.
Your headline basis as does the line like it was worth doing is. Children 20 there are 30 then up to you to estimate the length of the chain that.
So when you guess , then I guess compared to margins (left) or as compared to the preceding sequence
such as: %-20 then to %-30 his is approximate %-30 compare to %-20 or is %-30 so considering his margin
Not so, Ie you estimate the maximum long name 50 characters, you use %50 did you.
so 50 He printed characters including blank spaces spares parts + the name( as student ID,threats) not his right
ukm…
printf(“\n nhap student numbers n”);
Forums n front and rear of the upper various statements where he
same. are down and simultaneously.
Forums n forward is to line : Enter the number of students down the line .con sign n rear is taken down the line next statement should not he
Yeah you.
typedef struct sinhvien {
char MSV[20]; // Student code
char threats[30]; // cough Student Name
double toan, believe, you; // points toan, believe, you
} kieuSinhVien;
his place ko ni declaration :” sinhvien” which declared lun “kieuSinhvien” dc ko him. I saw that declaration, the type of structure “sinhvien” Where have you used !
ok, so are you ah.
He nguyenvanquan me hoi:
I have said above there 3 how to retrieve data components of the structure pointer :
How to 1: CNPMK10A[in].diemTB;
How to 2: (*(CNPMK10A i)).diemTB;
How to 3: (CNPMK10A i) ->diemTB;
I find it hard to understand the way 1 to take part in all the address pointers pointer ghost he writes:
px : Get the address to which it kept (point to)
*px : Get the value of the memory that it points to.
He helps me with incomprehensible spending too. Thank you.
Difficult to understand is how to use, That is the principle of it that.
honey.. thế em muốn tìm tên những sinh viên có điểm toán cao nhất thì làm như thế nào ạ 🙂
Then compare that to find, his normal comparison a> b then compares hour Ax> Bx is
C# có struct, vậy trong java có cái gì tương tự như struct k ( k tính đến class ở đây)
thực sự là mình chưa nắm vững về java nên mới hỏi câu này, có gì k phải mong b bỏ qua
Java không có struc bạn ah. Class có thể đảm nhiệm mọi thứ 😉
anh Quân ơi em có 1 thắc mắc nhỏ muốn anh làm sáng tỏ hộ em
Here is my code :
/* doc programming through a list khong 100 students including about:Ho ten, Year of Birth
1, DS Dua students out boys 1990
2, dua out dssv sorted alphabetically */
/* I wonder why the swap space character that can not be used: temp.ho_ten = LIST[in].ho_ten; list[in].ho_ten = LIST[j].threats; list[j]=temp.ho_ten; */
#include
#include
#include
typedef struct sinh_vien
{
char ho_ten[20];
int nam;
}SV;
main()
{
int n,in,j,T;
SV LIST[100],temp;
do{
printf(“Enter the dimensions brought n (0<n<=100):");
scanf("% D",&n);
}while(n100);
printf(“\n Enter the information for each student:\n”);
for(i=0;in<n;i )
{
printf("\n NHap ten cua sinh vien thu %d: ",i 1);
fflush(stdin); gets(list[in].ho_ten);
printf("\n nam sinh:");
scanf("% D",&list[in].male);
}
printf("\ndanh sach sinh vien khi chua sap xep:");
printf("\nstt Ho va ten nam sinh\n");
for(i=0;in<n;i ){
printf("%-2d %-20s %-4d\n",i + 1, LIST[in].ho_ten,list[in].male);
}
printf("\n danh sach cac sinh vien sinh nam 1990 the:\n");
for(i=0;in<n;i )
if(list[in].Men == 1990) printf("%-20s\n",list[in].ho_ten);
for(i=0;in<A-1;i )
for(j=i+1;j0) {temp = LIST[in]; list[in]= LIST[j]; list[j]=temp;}
}
printf(“Listings later arranged ki:\n”);
printf(“\Full name nstt boys n”);
for(i=0;in<n;i )
printf("%-2d %-20s %-4d\n",i + 1, LIST[in].ho_ten,list[in].male);
getch();
}
Swap, you must swap the interchangeable struc rather why each name?
Oh give me a question: you want to pass parameters to the function are pointers so structurally ntn? thanks!
For example, the structure is a desire to convey void(A *a)
printf(“%-20s% -30s% -7s% -7s% -7s n”, “MSV”, “Ho ten”, “Endeavor”, “Believe”, “English”);
printf(“%-20s %-30s %-7.2lf %-7.2lf %-7.2lfn”, sv1.MSV, sv1.hoten, sv1.toan, sv1.tin, sv1.anh);
printf(“%-20s %-30s %-7.2lf %-7.2lf %-7.2lfn”, sv2.MSV, sv2.hoten, sv2.toan, sv2.tin, sv2.anh);
explain giùm e v a
Just print out the screen is only you.
Waiter, let me ask: how to find the max of his Asia array structure?…^^
You use a for loop and then compared in the field you want. That's all
I asked him to arrange a lower student scores
you enter :
Ten diem
the 2
b 1
c 3
You do sort 2 number, his only change things when change both 1 struct student reviews.
I asked him to arrange a lower student scores
you enter :
Ten diem
the 2
b 1
c 3
———
the QA
Ten diem
the 3
b 2
c 1
the point is ,but why not name it according to the point where a dear students !
help children with.
When you have to change the struct exchange student rather.
Why should I have assigned SV2 = SV1 lah a ?! e do not understand this place very
Ah, then we assign a = b tendon like that
E sorry but e still do not understand what you mean very. SV1 SV2 = assigned only to transfer information or other purposes ?!
ad asked me,I have mentioned above is 3 how to access to retrieve data .Vay he could help her explain differences between 3 That way k ?(^-^)
Its results remain the same. With different just only you.
ad asked me to write a list of import and export functions, but do not be frequently used struct sv sir
You can use the array. VD Student named, age, point, I do 3 Name, age, point.
Closer ad guidelines ko sir DC. I do not understand it like this problem sir lam.ma:
Card readers information management needs including: code readers, name, ID, date
Year of Birth, sex, email, address, the date of the card and the card's expiration date (48 month
since the date of the card)
The program has the following functions:
1. Readers Management
the. See a list of readers in libraries
b. Add Readers
c. Edit information a reader
d. Clear information a reader
and. Search for ID card readers
f. Search for books by name
Card readers, it has what it needs, I do not use struct array if.
I let you research tks
à write this ad
#include
#include
void madocgia(int madg[])
{
for (int i = 0; in < 2; i )
{
printf("Nhap ma doc gia %d: ", in);
scanf_s("% D", &madg[in]);
}
}
void cmnd(int cm[])
{
for (int j = 0; j < 2; j )
{
printf("Nhap so CMND %d: ",j);
scanf_s("% D", &cm[j]);
}
}
void xuatma(int madg[])
{
for (int i = 0; in < 2; i )
{
printf("% D", madg[in]);
}
}
void xuatcm(int cm[])
{
for (int j = 0; j < 2; j )
{
printf("% D", cm[j]);
}
}
void main()
{
int a[100], b[100];
madocgia(the);
cmnd(the);
xuatma(the);
xuatcm(b);
_getch();
}
combinatorial algorithms listed in c ++ only been a few cases and then overwrite should ask yourself how you can make c ++ exported all cases without overwritten not? or programming program can list out all the cases of the combination not you?
You see Le Minh Hoang algorithm offline. Google is out
his troops. I want to ask what you want separated into the function as input into 1 print function 1 then how jaw sir. I saw him for all in function main.
Then you just write a separate function alone.
printf(“%d”, cm[j]); do you
To print the identification of the ith.
vd mo dau:
Star nhap duoc ko msv.
msv2 not clickable
Do you drifted command. I said above I got you, you replace command fflush_stdin(); the fflush(stdin) While the win code nhé. Their code in ubuntu should fflush_stdin();
#include
#include
typedef struct ngaythangnamsinh
{
int right,ladder,male;
}date;
typedef struct sinhvien
{
char ten[21];
char ms[11];
char lop[10];
date ns;
float dtb;
}sv;
void nhap1sv(sv &x)
{
printf(“\nnhap ho ten:”);fflush(stdin);gets(x.ten);
printf(“Enter code:”);fflush(stdin);gets(x.ms);
printf(“nhap lop:”);fflush(stdin);gets(x.lop);
printf(“Enter the date boys:”);
scanf(“%d% d% d” ,&x.ns.ngay,&x.ns.thang,&x.ns.nam);
printf(“Average entry point:”);fflush(stdin);scanf(“%f”,&x.dtb);
}
void xuat1sv(St. x)
{
printf(“\n ——— Student information —–\n”);
printf(“%-20s %-15s %-15s %-15s %-15sn”, “threats”, “MSSV”, “Lop”, “Birthday”, “DTB”);
printf(“%-20s %-15s %-15s %d-%d-%d f”,x.ten,x.ms,x.lop,x.ns.ngay,x.ns.thang,x.ns.nam,x.dtb);
}
void nhapdssv(St. and[],int n)
{
printf(“click dssv”);
for(int i=0;in<n;i )
{
printf("nhap vao thong tin sinh vien thu %:",i 1),
nhap1sv(the[in]);
}
}
int main()
{
St. x;
St. and[10];
int n;
nhapdssv(the,n);
nhap1sv(x);
xuat1sv(x);
}
aanh me ask you no error code but it does not run back loop sir?????
Because the value of n is not there you ah.
His stomach was rùi !!!Thanks!!!
He asked me my view
implementation jaw ok timslmax
xuatspslmax error function examination!!!
int timslmax(sp a[],int n)
{
int temp=a[0].sl;
for(int i=1;in<n;i )
{
if(temp<the[in].sl)
temp=a[in].sl;
}return temp;
}
void xuatspslmax(sp a[],int n)
{
int m = timslmax(the,n);
printf("san pham co sl max la:\n");
for(the[in].sl==m)
xuat1sp(the[in]);
}
int main()
{
sp x;
int n;
n=3;
sp a[10];
nhapdssp(the,n);
printf("%-20s %-15s %-15s\n","maso","tensp", "soluong");
xuatdssp(the,n);
xuatspslmax(the,n);
Structure function for(the[in].sl==m) Such is wrong then nothing.
He asked me how this error was sir although the program is still running normally.
57 2 C:\UsersAdminDocumentsbai2.c [Warning] passing argument 1 of ‘docsv’ from incompatible pointer type [enabled by default]
12 6 C:\UsersAdminDocumentsbai2.c [Note] expected ‘struct SV *’ but argument is of type ‘struct SV **’
#include
#include
typedef struct sinhvien{
char threats[50];
int dcc;
int dth;
int dck;
double dtb;
char xephang[10];
}SV;
void docsv(EN * EN){
printf(“ho ten:”);
gets(SV>threats);fflush(stdin);
printf(“\n”);
printf(“diem chuyyen can:”);
scanf(“%d”,&SV>dcc);printf(“\n”);
printf(“diem practice:”);
scanf(“%d”,&SV>dth);printf(“\n”);
printf(“endpoint ki:”);
scanf(“%d”,&SV>dCk);printf(“\n”);
}
double DTB(EN * EN){
return sv->dtb = SV>dcc*0.1+sv->dth * 0.3 + sv->dCk 0.06 *;
}
void insv(const SV * sv){
printf(“—–STUDENT INFORMATION—–\n”);
printf(“Ho ten:”);
printf(“%with”,SV>threats);
printf(“\n”);
printf(“attendance:”);
printf(“%d”,SV>dcc);
printf(“\n”);
printf(“diem practice:”);
printf(“%d”,SV>dth);
printf(“\n”);
printf(“endpoint ki:”);
printf(“%d”,SV>dCk);
printf(“\n”);
printf(“GPA:”);
printf(“%.2lf”,SV>dtb);
printf(“\n”);
printf(“Queue:”);
if(SV>dcc>=7&&SV>dth>= 4&&SV>dCk>=40)
printf(“the student”);
else printf(“Birth skiing”);
}
int main(){
EN * EN;
docsv(&sv);
DTB(&sv);
insv(&sv);
}
A think it is just a warning (Warning) stop, no fault.
e thank!!
So for more A A
Thank you very much !!!
His desire oi milk concerned a subject that how that he
Fix it first needs to be modified looking for, then enter the information for it alone.
thank you..
I did it..
Written over. Thank you very much committed
Thank you, sharing to friends anymore nhé.
The hi, Star of the e function subroutine, part of it is a function definition error unknow type of struct.
E C a solution dev.
How f @@ code?
cho em hoi cursor declaration in struct dc and want to get the value of the ash by then how a
have too. You view the list of links here will see. https://cachhoc.net/2014/12/21/lap-trinh-c-bai-13-danh-sach-lien-ket-don-cai-bang-con-tro/
He asked me sir, in place 2 Examples of keyword typedef, Between kieusinhvien sinhvien and then sinhvien is structured type we define, kieusinhvien is also variable structure type sinhvien not it? I ask this because things do not understand attention 2 sir, if say this attention there is kieusinhvien skin structure type we define gone, expecting him to answer.
using keywords typdef it is kieusinhvien 1 type.
CEO:
int a // => A variable
// typedef int a => a similar type is int.
British Army for you to ask is when used in its struct * ?
For example, when I read the part Treap then declaring struct node ntn :
struct Node
{
int priority;
int sz;
int value;
Node * l,*r;
};
Why the Node l,r Back to add * in front
Oil * means that the variable is a pointer => Always use the cursor, the user needs *.
British troops have questions dear brother in the swapped in struct:
example: struct the Student Sv [n] ; including name and location.
apart from the name and the location change in turn may change always Sv[ in ] with Sv[ i 1 ] OK
đk nhé.
but what makes kind sir ..!
Kids create a new struct to mediate without
struct the Student Sv [n];
struct SinhVien temp = Sv[0] ;
sv[0] = E[3] ;
sv[3] = temp ;
Waiter,let me ask this code wrong somewhere e Here '?.I used fflush(stdin) how many times it has been the command error drift.(the code simply enter listing information alone sir).
#include
#include
#include
struct diachi {
char * = quan_huyen(tank *)malloc(10*sizeof(tank));
char *to=(char *)malloc(10);
};
struct danhba{
int sdt;
Char * Hoten =(char *)malloc (30);
compile their diachi;
}*danhbadt =(danhba *)malloc(40);
danhba newi(danhba *a){
printf(“New phone number : “);
scanf(“%d”,&a->tsp);
fflush(stdin);
printf(“Full name of the owner : “);
gets(a->threats);
fflush(stdin);
printf(“districts : “);
gets(a->canhan.quan_huyen);
fflush(stdin);
printf(“to (phuong) : “);
gets(a->canhan.to);
}
int main(){
int chon;
printf(“__________________________________n”);
printf(“1. enter new information n”);
printf(“2. Find phone numbers n”);
printf(“3. loc phone number at the address n”);
scanf(“%d”,&chon);
switch(chon){
case 1: newi(danhbadt);
break;
}
}
I drifted in what to order? Referring to the principle that after entering the number that entered the chain, remove stdin.
e were wrong in that enter “quan_huyen” and enter “to” sir. Try deleting e stdin multiple times and still not be.
How wrong you? Not be imported or entered but not processed?
a cup e may ask students enter , Export graduates 2 not a separate function dc?
have too.
to ask you dear, its dc switch do not master menu
its not understand you.
I asked my darling for a list and then want to transfer the components you want, then what to do sir
Themselves do not understand your question.
His articles are easy to understand, e wrote 1 simple all tested, although not error but did not enter dc student code which jumps to always name the students, a viewing households e vs:
#include
#include
using namespace std;
struct sv {
char maSv[30], ten[30];
int soMon;
};
void main() {
int n, in;//n is the number of students
cout <> n;
struct sv stt[100];//numerical order
for (i = 0; in < n; i ) {
#define g stt[in]
cout << "\nNhap thong tin cua sinh vien thu " << in + 1;
cout << "\nMa sinh vien : "; fflush(stdin);// This paragraph does not enter that jump down dc sv always
fgets(g.maSv, 30, stdin);
cout << "\nTen sinh vien : ";
fflush(stdin);
fgets(g.ten, 30, stdin);
cout <> g.soMon;
}
}
Import command cout<>Your n lo sai…
a correct e households with, f copy machine materials in the following article, posted shall be so, e code runs dc and that
You review all the 2, Items ordered drifting nhé.
e view code level then, post to be changed a few seats, eg place of e #include posted missing the following,
cin >> n converted cout n, cin >> g.soMon converted cout g.soMon