아래 코드는 supposed
이며 단계별로 사용자에게 정보를 제공합니다. 그러나 현재는 정보를 기다리고 다음은 제공된 내용과 프롬프트를 표시합니다. 왜 이런 일이 일어 났는지 설명 할 수 있습니까? 감사.메시지 확인 및 저장에 대한 도움말
contacts.h 파일
struct contacts {
int phone_number;
char first_name[11], last_name[11];
};
rolodex.c 파일
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "contacts.h"
int main(int argc, char* argv[]) {
struct contacts* c = (struct contacts*) malloc(sizeof(struct contacts));
if (c == 0) {
return 1;
}
set_first_name(c);
set_last_name(c);
set_phone_number(c);
display_contact(c);
}
int set_first_name(struct contacts* c) {
puts("\nWhat is your first name? ");
gets(c->first_name);
return 0;
}
int set_last_name(struct contacts* c) {
puts("\nWhat is your last name? ");
gets(c->last_name);
return 0;
}
int set_phone_number(struct contacts* c) {
printf("\nWhat is your phone number? ");
scanf(" %d", &c->phone_number);
return 0;
}
int display_contact(struct contacts* c) {
printf("\nName: %s %s Number: %d", c->first_name, c->last_name, c->phone_number);
return 0;
}
'gets()'를 사용하지 마십시오. 안전하지 않으며 안전하지 못합니다. 'fgets()'대신'fgets (c-> last_mame, sizeof c-> last_name, stdin); ' – pmg
+1'을 사용하라. – pmg