#pragma warning(disable : 4996)
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<string.h>
typedef struct Student {
char name[50];
int age;
char address[20];
char stno[10];
}; St;
int main() {
St st1, temp_st;
int i = 0, j = 0;
strcpy(st1[0].name, "홍길동1");
st1[0].age = 25;
strcpy(st1[0].address, "AA st.ba");
strcpy(st1[0].stno, "2022312178");
strcpy(st1[1].name, "홍길동2");
st1[1].age = 22;
strcpy(st1[1].address, "AA st.bb");
strcpy(st1[1].stno, "2022142178");
strcpy(st1[2].name, "홍길동3");
st1[2].age = 21;
strcpy(st1[2].address, "AA st.bc");
strcpy(st1[2].stno, "2022367178");
strcpy(st1[3].name, "홍길동4");
st1[3].age = 29;
strcpy(st1[3].address, "AA st.bd");
strcpy(st1[3].stno, "2022398178");
strcpy(st1[4].name, "홍길동5");
st1[4].age = 28;
strcpy(st1[4].address, "AA st.be");
strcpy(st1[4].stno, "2022333178");
for (i = 0; i < 5; i++) {
for (j = 0; j < 5 - i; j++) {
if (st1[j].age > st1[j + 1].age) {
temp_st = st1[j];
st1[j] = st1[j + 1];
st1[j + 1] = temp_st;
}
}
}
for (i = 0; i < 5; i++) {
printf("%s\n", st1[i].name);
printf("%d\n", st1[i].age);
printf("%s\n", st1[i].address);
printf("%s\n", st1[i].stno);
printf("ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ\n");
}
return 0;
}
st1,temp_st가 정의되어있지않다고하는데 어떻게 바꿔야하나요?
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<string.h>
typedef struct Student {
char name[50];
int age;
char address[20];
char stno[10];
}; St;
int main() {
St st1, temp_st;
int i = 0, j = 0;
strcpy(st1[0].name, "홍길동1");
st1[0].age = 25;
strcpy(st1[0].address, "AA st.ba");
strcpy(st1[0].stno, "2022312178");
strcpy(st1[1].name, "홍길동2");
st1[1].age = 22;
strcpy(st1[1].address, "AA st.bb");
strcpy(st1[1].stno, "2022142178");
strcpy(st1[2].name, "홍길동3");
st1[2].age = 21;
strcpy(st1[2].address, "AA st.bc");
strcpy(st1[2].stno, "2022367178");
strcpy(st1[3].name, "홍길동4");
st1[3].age = 29;
strcpy(st1[3].address, "AA st.bd");
strcpy(st1[3].stno, "2022398178");
strcpy(st1[4].name, "홍길동5");
st1[4].age = 28;
strcpy(st1[4].address, "AA st.be");
strcpy(st1[4].stno, "2022333178");
for (i = 0; i < 5; i++) {
for (j = 0; j < 5 - i; j++) {
if (st1[j].age > st1[j + 1].age) {
temp_st = st1[j];
st1[j] = st1[j + 1];
st1[j + 1] = temp_st;
}
}
}
for (i = 0; i < 5; i++) {
printf("%s\n", st1[i].name);
printf("%d\n", st1[i].age);
printf("%s\n", st1[i].address);
printf("%s\n", st1[i].stno);
printf("ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ\n");
}
return 0;
}
st1,temp_st가 정의되어있지않다고하는데 어떻게 바꿔야하나요?
}; St;
어디에 적으라는건가요?
라고 적으셨는데 } St;로 바꿔보셈 ㅇㅅㅇ
식에 개체포인터 형식이 있어야하는데 St형식이 있다고 오류가떠요
st1[0].name 이걸 st1.name[0] 일케 바꿔보셈
age부분은 str[0].age로하면 St형식있다고 오류뜨고 str.age[0]으로하면 int형식있다고 오류뜨네용
name은 배열이라서 []를 붙이고 age는 []를 붙일 필요 없는데 st1에 []은 왜 붙이고 계신거
St st1, temp_st; 이게 st1 선언 같은데