C/C++の宿題を片付けます 83代目
■ このスレッドは過去ログ倉庫に格納されています
0145デフォルトの名無しさん
2007/02/11(日) 21:44:53#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct{
char *name;
char *address;
}ADDR;
int main(void){
char buf[512];
ADDR *temp;
if((temp = malloc(sizeof(ADDR))) == NULL)return EXIT_FAILURE;
printf("名前:");
fgets(buf, sizeof(buf), stdin);
if((temp->name = malloc(strlen(buf) +1)) == NULL)return EXIT_FAILURE;
strcpy(temp->name, buf);
printf("住所:");
fgets(buf, sizeof(buf), stdin);
if((temp->address = malloc(strlen(buf) +1)) == NULL)return EXIT_FAILURE;
strcpy(temp->address, buf);
printf("\n名前:%s住所:%s",
temp->name, temp->address
);
return EXIT_SUCCESS;
}
■ このスレッドは過去ログ倉庫に格納されています