C言語のプログラムに独自性を出したいです。
Posted: 2010年10月30日(土) 18:38
友人のプログラムを自分なりにいじってみたのですが、どうしても似たままです。
下にプログラムを載せるので何かアイデアがあれば教えてください。
#include <stdio.h>
#include <stdlib.h>
typedef struct friend sFriend;
struct friend{
int ID;
int Age;
int Name[20];
char *Address;
sFriend *next;
};
sFriend header;
void insert(void)
{
sFriend *p, *newcell;
p=&header;
while( p->next != NULL){
p=p->next;
}
newcell = (sFriend*)malloc( sizeof(sFriend) );
printf("ID:"); scanf("%d",&newcell->ID);
printf("年齢:"); scanf("%d",&newcell->Age);
printf("名前:"); scanf("%d",&newcell->Name);
printf("住所:"); scanf("%s",&newcell->Address);
newcell->next = NULL;
p->next = newcell;
}
void show_Address(void)
{
int i=0;
sFriend *p, *q[10];
p=&header;
while(p->next != NULL){
p=p->next;
printf("%d人目:%p\n",i+1,p);
q=p;
if(i>=1){
printf("アドレスの差:%d\n",(long)q-(long)q[i-1]);
}
i++;
}
}
int main(void)
{
int a=0, x, y,c;
header.next=NULL;
while(a!=2){
printf("情報の入力:1、情報の表示:2 "); scanf("%d",&a);
if(a==1){
insert();
}
if(a==2){
printf("構造体の大きさ:%u\n",sizeof(sFriend));
printf("構造体の各項目のデータサイズ\n");
printf("ID:%u\n",sizeof(header.ID));
printf("年齢:%u\n",sizeof(header.Age));
printf("名前:%u\n",sizeof(header.Name));
printf("住所:%u\n",sizeof(header.Address));
printf("次の友達へのポインタ:%u\n\n",sizeof(header.next));
printf("<各インスタンスの格納されたアドレス>\n");
show_Address();
}
}
return 0;
}
下にプログラムを載せるので何かアイデアがあれば教えてください。
#include <stdio.h>
#include <stdlib.h>
typedef struct friend sFriend;
struct friend{
int ID;
int Age;
int Name[20];
char *Address;
sFriend *next;
};
sFriend header;
void insert(void)
{
sFriend *p, *newcell;
p=&header;
while( p->next != NULL){
p=p->next;
}
newcell = (sFriend*)malloc( sizeof(sFriend) );
printf("ID:"); scanf("%d",&newcell->ID);
printf("年齢:"); scanf("%d",&newcell->Age);
printf("名前:"); scanf("%d",&newcell->Name);
printf("住所:"); scanf("%s",&newcell->Address);
newcell->next = NULL;
p->next = newcell;
}
void show_Address(void)
{
int i=0;
sFriend *p, *q[10];
p=&header;
while(p->next != NULL){
p=p->next;
printf("%d人目:%p\n",i+1,p);
q=p;
if(i>=1){
printf("アドレスの差:%d\n",(long)q-(long)q[i-1]);
}
i++;
}
}
int main(void)
{
int a=0, x, y,c;
header.next=NULL;
while(a!=2){
printf("情報の入力:1、情報の表示:2 "); scanf("%d",&a);
if(a==1){
insert();
}
if(a==2){
printf("構造体の大きさ:%u\n",sizeof(sFriend));
printf("構造体の各項目のデータサイズ\n");
printf("ID:%u\n",sizeof(header.ID));
printf("年齢:%u\n",sizeof(header.Age));
printf("名前:%u\n",sizeof(header.Name));
printf("住所:%u\n",sizeof(header.Address));
printf("次の友達へのポインタ:%u\n\n",sizeof(header.next));
printf("<各インスタンスの格納されたアドレス>\n");
show_Address();
}
}
return 0;
}