기본적으로 나는 5 개의 다른 "웹 사이트"에 대한 암호 관리자 역할을하는 프로그램을 만들어야합니다. 함수와 주요 메소드를 하나의 파일에 모두 선언하면 완벽하게 실행됩니다. 의 요소 : 나는 헤더 파일을 사용하지만 때 나는배열 요소에 불완전한 타입이 있습니다.
functions.h
#ifndef FUNCTIONS_H_
#define FUNCTIONS_H_
struct entry;
void requestEntry(struct entry *data);
void displaySummary(struct entry *data);
void displayEntry(struct entry *data);
#endif
functions.c
#include <stdio.h>
#include "functions.h"
struct entry{
char webName[32];
char userName[32];
char password[32];
};
void requestEntry(struct entry *data){
printf("Please enter the following items: \n");
printf("Website name: ");
scanf("%s", data->webName);
printf("Username: ");
scanf("%s", data->userName);
printf("Password: ");
scanf("%s", data->password);
}
void displaySummary(struct entry *data){
printf(" - %s\n", data->webName);
}
void displayEntry(struct entry *data){
printf("Website: %s\n", data->webName);
printf("Username: %s\n", data->userName);
printf("Password: %s\n", data->password);
}
main.c를
#include <stdio.h>
#include <stdbool.h>
#include "functions.h"
int main()
{
struct entry sites[5];
for (int i = 0; i < 5; i++){
requestEntry(&sites[i]);
}
printf("\n");
printf("Summary: \n");
for (int i = 0; i < 5; i++){
printf("%d", (i + 1));
displaySummary(&sites[i]);
}
bool cont = true;
int i;
while (cont){
printf("Type in a number from 1 to 5 to pull up the entry, or type 0 to exit: ");
scanf("%d", &i);
if (i == 0){
cont = false;
continue;
}
printf("\n");
displayEntry(&sites[i - 1]);
}
}
ERROR 표시되는 오류 배열 '입력 사이트 [5]'형식이 불완전합니다
다른 IDE에서 프로그램을 빌드하려고 시도한 결과, 배열 크기가 너무 커서 5 개의 구조체가 분명히 구성되었다고합니다. 나는 모든 것이 하나의 파일에있을 때 완벽하게 실행된다고 말했기 때문에 내가 가지고있는 코드가 작동한다는 것을 알고있다.
'main()'이'struct entry' *가 어떻게 생겼는지에 대해 알고있는 자신에게 물어보십시오. 그것의 정의 *는 또 다른 .c 파일에 묻혀있다. 당신이 이것을 할 것인지를 알아야 할 필요가 있습니다 :'struct entry sites [5];' – WhozCraig
"struct entry"의 정의를 .c 파일로 옮깁니다. –