#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define SIZE 25
#define NUM_EMP 3
void printEmployees (Employees [NUM_EMP], int c);
typedef struct employee
{
char fname[20];
char lname[20];
int id;
char dependents [3][20];
} Employees;
void printEmployees(Employees [NUM_EMP], int c) {
//a function to print what's written in the struct
printf("%s", Employees[0].fname);
printf("%s", Employees[0].lname);
printf("%d", Employees[0].id);
printf("%s", Employees[0].dependents);
}
int main() {
//populating the struct above
Employees[NUM_EMP] {
{"Juan", "Libero", 1, {"son", "daughter", "dog"}},
{"Stan", "Smith", 2, {"daughter", "daughter", "dog"}},
{"Russell", "Green", 3, {"son", "son", "cat"}},
}
Employees [NUM_EMP];
printEmployees(Employees,3);
}
저는 지금 프로젝트를 진행하고 있습니다. 제 목표는 main () 아래에있는 내용을 인쇄하는 것입니다.이 정보는 구조체에 입력하려고했지만 변경할 수 없습니다. 구조체에서 메인에있는 정보를 인쇄하고 싶지만 계속 오류가 발생하고 수정 방법을 모르겠습니다. 나를 도울 수있는 사람이 있습니까?
문제는 구조체 변수가 없다는 것입니다. Employees
의 약자로 사용되는 유형일 뿐이며 다음과 같이 struct employee
작동합니다.
void printEmployees(Employees persons[], int c);
void printEmployees(Employees persons[], int c) {
//a function to print what's written in the struct
printf("%s ",persons[0].fname);
printf("%s ", persons[0].lname);
printf("%d ", persons[0].id);
printf("%s\n", persons[0].dependents);
}
int main() {
//populating the struct above
Employees persons[NUM_EMP] = {
{"Jackson", "Leverock", 1, {"son", "daughter", "dog"}},
{"Stan", "Smith", 2, {"daughter", "daughter", "dog"}},
{"Russell", "Green", 3, {"son", "son", "cat"}},
};
printEmployees(persons,3);
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다