C의 구조체에서 인쇄하는 방법, 내가 뭘 잘못하고 있는지 잘 모르겠고 코드의 모든 부분에서 다양한 오류가 계속 발생합니까?

BlueSkies21
#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 () 아래에있는 내용을 인쇄하는 것입니다.이 정보는 구조체에 입력하려고했지만 변경할 수 없습니다. 구조체에서 메인에있는 정보를 인쇄하고 싶지만 계속 오류가 발생하고 수정 방법을 모르겠습니다. 나를 도울 수있는 사람이 있습니까?

alex01011

문제는 구조체 변수가 없다는 것입니다. 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] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관