main.c で People, data, pdata を使うには、
どこを修正すればよいのでしょうか。
extern typedef struct {
としてもダメでした。
typedef struct {
shell
1gcc People.c main.c 2main.c: In function ‘main’: 3main.c:4: error: ‘People’ undeclared (first use in this function) 4main.c:4: error: (Each undeclared identifier is reported only once 5main.c:4: error: for each function it appears in.) 6main.c:4: error: expected ‘;’ before ‘data’ 7main.c:5: error: ‘pdata’ undeclared (first use in this function) 8main.c:7: error: ‘data’ undeclared (first use in this function)
C
1/* main.c */ 2 3int main() { 4 People data; 5 People *pdata; 6 7 pdata = &data; 8 9 InputPeople(pdata); 10 ShowPeople(data); 11 12 return 0; 13}
C
1/* People.h */ 2 3#ifndef __PEOPLE_H__ 4#define __PEOPLE_H__ 5 6#include <stdio.h> 7#include <string.h> 8 9typedef struct { 10 char name[256]; 11 int age; 12 int sex; 13} People; 14 15/* 個人データを入力する */ 16extern void InputPeople(People *pdata); 17 18/* 個人データを出力する */ 19extern void ShowPeople(People data); 20 21#endif
C
1/* People.c */ 2 3#include "People.h" 4 5void InputPeople(People *pdata) { 6 printf("名前: "); 7 scanf("%s", pdata->name); 8 printf("年齢: "); 9 scanf("%s", &pdata->age); 10 printf("性別(1-男性, 2-女性: "); 11 scanf("%s", &pdata->sex); 12 printf("\n"); 13} 14 15void ShowPeople(People data) { 16 char sex[16]; 17 18 printf("名前:%s\n", data.name); 19 printf("年齢:%d\n", data.age); 20 21 if (data.sex == 1) { 22 strcpy(sex, "男性"); 23 } else { 24 strcpy(sex, "女性"); 25 } 26 27 printf("性別:%s\n", sex); 28 printf("\n"); 29}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/05 17:07