By GokiSoft.com|
09:32 23/12/2020|
Lập Trình C
[Share Code] Tìm hiểu struct lập trình C - Khóa học lập trinh C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
typedef int SO_NGUYEN;
typedef unsigned int SO_NGUYEN_DUONG;
struct Student_ST {
char name[50], address[200];
int age;
};
typedef struct Student_ST Student;
typedef struct Animal_ST {
char name[50], foodType[30];
int age;
} Animal;
int main(int argc, char *argv[]) {
//struct
struct Student_ST std;
Student std1;
printf("\nNhap ten sinh vien: ");
gets(std.name);
printf("\nTen: %s", std.name);
Animal animal;
printf("\nNhap ten dong vat: ");
gets(animal.name);
puts(animal.name);
//Khai bao 1 mang gom 5 thang sinh vien
Student studentList[5];
int i;
//Nhap vao 5 sinh vien
for(i=0;i<5;i++) {
printf("\nNhap thong tin sinh vien thu %d", i+1);
printf("\nNhap ten: ");
fflush(stdin); fflush(stdout);
gets(studentList[i].name);
printf("\nNhap tuoi: ");
fflush(stdin); fflush(stdout);
scanf("%d", &studentList[i].age);
}
//Hien thi danh sach sinh vien
for(i=0;i<5;i++) {
printf("\nSinh vien (%d): Ten -> %s, tuoi -> %d", i+1, studentList[i].name, studentList[i].age);
}
/**
//Tim hieu typedef trong lap trinh C
int x = 5;
SO_NGUYEN k = 10;
unsigned int u = 9;
SO_NGUYEN_DUONG m = 10;
printf("\nk = %d", k);
printf("\nk = %d", u);
*/
/**
//Tim hieu ve string
char str[30];
printf("\nNhap str = ");
// scanf("%s", str);
gets(str);
printf("\nstr = %s", str);
char s1[30], s2[30], c;
printf("\nNhap s1 = ");
fflush(stdin);fflush(stdout);
gets(s1);
printf("\nNhap s2 = ");
fflush(stdin);fflush(stdout);
gets(s2);
printf("\nNhap c = ");
fflush(stdin);fflush(stdout);
scanf("%c", &c);
// char *p = strchr(s1, c);
char *p = strstr(s1, s2);
printf("\nKet qua: %s", p);
*/
return 0;
}
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)