C言語で生徒の名前とテストの点数を辞書順に表示するプログラムの作成方法を教えてください。

このQ&Aのポイント
  • C言語で生徒の名前とテストの点数を辞書順に表示するプログラムの作成方法を教えてください。
  • 生徒の名前とテストの点数を入力し、辞書順にソートして表示するC言語のプログラムを作りたいです。
  • C言語で生徒の名前とテストの点数を管理するプログラムを作成していますが、名前を辞書順にソートする方法がわかりません。教えてください。
回答を見る
  • ベストアンサー

あと少しの所なので教えてください><

C言語について質問です。↓のような生徒の名前とテストの点数を表示させるプログラムをつくってほぼできているのですが。。生徒の名前を辞書順、(abc順)にするところで悩んでいます、教えてください。 長くなってますがそんなに難しくはないのでお願いします。 #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct student{ char name[20]; int eng; int math; struct student *next; }lst; lst *root=NULL; void attach(char *n,int e,int m) { lst *newp,*p; newp=(lst *)malloc(sizeof(lst)); if(newp==NULL){ fprintf(stderr,"エラーです\n"); exit(1); } strncpy(newp -> name,n,20); newp -> eng =e; newp -> math=m; newp -> next=NULL; if(root==NULL){ root=newp; } else{ for(p=root;(p ->next)!=NULL;p=p -> next); p -> next=newp; } } void delete(char *n) { lst *p,*tmp; if(root!=NULL){ if(strncmp(root ->name,n,20)==0){ tmp=root -> next; free(root); root=tmp; } else { for(p=root;(p -> next)!=NULL;p= p -> next){ if(strncmp(p->next->name,n,20)==0){ tmp= p->next->next; free(p -> next); p -> next = tmp; break; } } } } } void printlst() { lst *p; if(root==NULL){ printf("リストは空です\n"); } else { p=root; do { printf("名前: %s\n",p->name); printf("英語: %d\n",p->eng); printf("数学: %d\n",p->math); printf("\n"); p=p->next; }while(p!=NULL); } } int lexorder(char s1[],char s2[]) { int i; for(i=0;;i++){ if(s1[i]<s2[i]) return(-1); if(s1[i]>s2[i]) return(1); if(s1[i]=='\0'&&s2[i]=='\0') return(0); } } void insert(char *n,int e,int m) { lst *newp,*p; newp=(lst *)malloc(sizeof(lst)); if(newp==NULL){ fprintf(stderr,"エラー:メモリーの確保に失敗しました。\n"); exit(1); } strncpy(newp->name,n,20); newp->eng=e; newp->math=m; newp->next=NULL; if(root==NULL||lexorder(n,root->name<=0)){ newp->next=root; root=newp; }else { //ここです } } int main() { root=NULL; attach("alice",80,73); attach("bob",90,80); attach("carol",72,95); attach("dave",82,65); attach("charlie",0,0); delete("bob"); delete("alice"); printlst(); } int lexorderは並びをかえるためのものでたぶんできていてvoid insertも先頭に入れるプログラムはできたのですが2番目以降に入れるプログラムを//ここです。の所がうまく書けません><教えて下さい><お願いします。

質問者が選んだベストアンサー

  • ベストアンサー
回答No.2

attach関数とinsert関数の2つを用意する意味がわかりません。データ登録時はinsert関数を用いて、適切な場所に挿入すればよいのでは? lexorder関数の仕様もよく分かりません。 lexorder(n,root->name<=0) で呼び出すということは第一引数がn 第二引数がroot->name<=0となりますが、 root->nameはchar*型ですから、root->name<=0 として何の意味があるのでしょうか? 正しくセットされているポインタが負数になることはないと思います。 もしかしたら、 strcmp(n,root->name)<=0 でよいのでは? リスト構造に昇順や降順に追加していくプログラム例は以下のサイトにあります。参考になるのではないでしょうか? http://www.geocities.jp/ky_webid/algorithm/010.html

その他の回答 (1)

  • asuncion
  • ベストアンサー率33% (2126/6288)
回答No.1

リスト構造を使わねばならない、という条件があるのですか?

u_f_o_pech
質問者

お礼

ありがとうございました。

関連するQ&A

  • あと少しの所なので教えてください><

    C言語で名前と成績を並べるプログラムを書いてみたのですがコンパイラは通るもののうまくいきません><教えて下さい><長いですがそんなに難しくないのでお願いします>< #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct student{ char name[20]; int eng; int math; struct student *next; }lst; lst *root=NULL; void attach(char *n,int e,int m) { lst *newp,*p; newp=(lst *)malloc(sizeof(lst)); if(newp==NULL){ fprintf(stderr,"エラーです\n"); exit(1); } strncpy(newp -> name,n,20); newp -> eng =e; newp -> math=m; newp -> next=NULL; if(root==NULL){ root=newp; } else{ for(p=root;(p ->next)!=NULL;p=p -> next); p -> next=newp; } } void delete(char *n) { lst *p,*tmp; if(root!=NULL){ if(strncmp(root ->name,n,20)==0){ tmp=root -> next; free(root); root=tmp; } else { for(p=root;(p -> next)!=NULL;p= p -> next){ if(strncmp(p->next->name,n,20)==0){ tmp= p->next->next; free(p -> next); p -> next = tmp; break; } } } } } void printlst() { lst *p; if(root==NULL){ printf("リストは空です\n"); } else { p=root; do { printf("名前: %s\n",p->name); printf("英語: %d\n",p->eng); printf("数学: %d\n",p->math); printf("\n"); p=p->next; }while(p!=NULL); } } void insert(char *n,int e,int m) { lst *newp,*p; newp=(lst *)malloc(sizeof(lst)); if(newp==NULL){ fprintf(stderr,"エラー:メモリーの確保に失敗しました。\n"); exit(1); } strncpy(newp->name,n,20); newp->eng=e; newp->math=m; newp->next=NULL; if(strcmp(n,root->name)<=0){ newp->next=root; root=newp; } else { //ここです。 p=newp->next->next; newp->next->next=newp->next; newp=p; } } int main() { root=NULL; attach("alice",80,73); attach("bob",90,80); attach("carol",72,95); attach("dave",82,65); attach("charlie",0,0); delete("bob"); delete("alice"); printlst(); insert("charlie",0,0); } という感じなんですがvoid insertのところで先頭のcarolを入れると大丈夫なんですが2番目以降に入るはずのdaveやcharlieを入れるとBus errorとでてしまうので2番目以降に入れるためのプログラム void insertの//ココです。の所の書き方が間違っているんだと思います。どなたか教えてください><お願いします。 補足 void attachがメンバを書き込むもの。 delateが消去。 void insertが辞書順にするもので、たぶん問題はここの最後です。お願いします><

  • セグメンテーション違反が出てしまいます・・・.

    #include<stdio.h> typedef struct tag{ int num; char name[10]; struct tag *next; }DATA; void add(void); DATA *head,*wp,*back; int main(void) { FILE *rfp,*wfp; char buf[256]; DATA *p; head=NULL; //ファイルを読み込み--------------------------- rfp=fopen("sample.txt", "r"); while(fgets(buf,256,rfp)!=NULL){ p=(DATA *)malloc(sizeof(DATA)); sscanf(buf,"%d %s", &(p->num),p->name); if(head==NULL){ head=p; head->next=NULL; back=p; } else{ back->next=p; back=p; } p->next=NULL; } fclose(rfp); //読み込み終了--------------------------------- } void add(void){ DATA *newp; newp=(DATA *)malloc(sizeof(DATA)); scanf("%d", &newp->num); scanf("%s", &newp->name); newp->next=NULL; for(wp=head; wp!=NULL; wp=wp->next){ if(head=NULL)head=newp; else if(newp->num < wp->num){ head->next = newp; } } } sample.txtからデータを読み込みそれを構造体のリスト構造にしてその構造体にデータを追加したいのですが、最後のhead->next=newpのところでセグメンテーション違反が出てしまいます。なぜでしょうか? 恐らくプログラムの内容はあまりないと思いますので概要だけ汲み取ってくれたら嬉しいです。因みにadd関数は途中です。

  • リストの削除について(構造体)

    リストの削除のプログラムを実行して行ってみると、リストの削除処理中にプログラムが終わって変更後処理がうまく表示されません。どこが間違っているかが分からないしだいです。返答のほどよろしくお願いいたします。 #include<stdio.h> #include<malloc.h> #include<string.h> struct list{ char name[20]; int age; struct list *next; }; void main(void) { struct list *head, *p, *n, *old; char key[20]; /*ダミーノード作成*/ head = (struct list*)malloc(sizeof(struct list)); old = head; while(p = (struct list*)malloc(sizeof(struct list)), printf("name age入力\n"), scanf("%s %d", p -> name, &p -> age) != EOF){ old -> next = p; old = p; } free(p); old -> next = NULL; p = head -> next; printf("変更前リスト\n"); while(p != NULL){ printf("name:%s age:%d\n",p -> name, p -> age); p = p -> next; } printf("削除key入力(name)\n"); gets(key); n = head; while(n != NULL){ old = n; n = n -> next; //printf("n -> name %s\n", n -> name); if(strcmp(n -> name, key) == 0){ printf("%s削除\n", key); //printf("n -> name %s old -> name %s\n", n -> name, old -> name); old -> next = n -> next; } } p = head -> next; printf("変更後リスト\n"); while(p != NULL){ printf("name:%s age:%d\n", p -> name, p -> age); p = p -> next; } }

  • 二進検索木

    下記のプラグラムで二進検索木を作りたいのですが、うまくいきません(2つまでしか保存ができない)。 たぶん、ポインタがおかしいと思うのですが・・・。お願いします。 入力 年齢 1 名前 a メアド a@ 年齢 2 名前 b メアド b@ 年齢 3 名前 c メアド c@ 年齢 -1 出力 b  ×  c   ×   × 歳 2 名前 b メアド b@ 歳 3 名前 c メアド c@ #include<stdio.h> #include<stdlib.h> struct node{ char *name; char *email; int age; struct node *left; struct node *right; }; void getline(char *s,int n){ int c; while(--n>0&&((c=getchar())!=EOF && c!='\n')) *s++=c; *s='\0'; } char* dupstr(char* strg){ char* newstr; newstr = (char*)malloc(sizeof(char)*strlen(strg)); strcpy(newstr,strg); return newstr; } struct node *new(int n,char *na,char *em){ struct node *p; p=malloc(sizeof(struct node)); p->age=n; p->name=na; p->email=em; p->left=NULL; p->right=NULL; return p; } void print(struct node *p){ if(p==NULL)return; else{ print(p->left); printf("\n歳:%d ", p->age); printf("\n名前:%s ", p->name); printf("\nメアド:%s ", p->email); print(p->right); } } void print_tree(struct node *p,int level){ int i; for(i=0;i<level;i++)printf(" "); if(p==NULL)printf("×\n"); else{ printf("%s\n",p->name); print_tree(p->left,level+1); print_tree(p->right,level+1); } } void *insert(struct node *p,int n,char *na,char *em){ int c; c=strcmp(p->name,na); if(c==0); else if(c>0){ if(p->left==NULL) {p->left=new(n,na,em); return p;} else insert(p->left,n,na,em); } else{ if(p->right==NULL){ p->right=new(n,na,em); return p;} else insert(p->right,n,na,em); } } main() { int age,g; char buf[80],a[80],b[80],*email,*name; struct node *root=NULL; g=1; printf("\n歳を入力:"); getline(buf,sizeof(buf)); printf("\n名前入力:"); getline(a,sizeof(a)); name=dupstr(a); age=atoi(dupstr(buf)); printf("\nメアド入力:"); getline(b,sizeof(b)); email=dupstr(b); root=new(age,name,email); while(g==1){ printf("\n歳を入力:"); getline(buf,sizeof(buf)); age=atoi(dupstr(buf)); if(age==-1) break; printf("\n名前入力:"); getline(a,sizeof(a)); name=dupstr(a); printf("\nメアド入力:"); getline(b,sizeof(b)); email=dupstr(b); root=insert(root,age,name,email); } print_tree(root,0); print(root); }

  • プログラミングのポインタの所の課題で、途中までやったのですが・・・

    プログラミングのポインタの所の課題で、途中までやったのですが・・・ どうしてもとけません。どなたか解けるかた、ご指導お願いします。。。 課題は以下の通りです。 1.文字配列の先頭文字でソートを行って出力するプログラムを完成させよ。ただし、my_sort_stringsはポインタ配列とその要素数を引数として、登録されている文字配列を昇順に並べ替える関数である。 #include<stdio.h> #include<string.h> void print_strings(char **p, int n); void swap_strings(char **p, int i, int j); int min_index(); void my_sort_strings(); int main() { char*p[100]; char Orange[] = "orange"; char Apple[] = "apple"; char Peach[] = "peach"; char Grape[] = "grape"; char Melon[] = "melon"; int i; p[0] = Orange; p[1] = Apple; p[2] = Peach; p[3] = Grape; p[4] = Melon; print_strings(p, 5); my_sort_strings(); print_strings(p, 5); return 0; } void print_strings(char **s, int n) { int i; printf("-----------begin: print_string ----------\n"); printf("print_string: s's value: %08x\n", s); for(i = 0; i < n; i++) { printf("(s[%d])'s value: %08x\n", i, s[i]); printf("(s[%d])'s address: %08x\n", i, &s[i]); } for(i = 0; i < n; i++) printf("%d: %s\n, i, s[i]"); printf("-----------end: print_strings-----------\n"); } void swap_strings(char **p, int i, int j) { char *tmp; tmp = p[i]; p[i] = p[j]; p[j] = tmp; } int min_index(char **a, int n) { } void my_sort_strings( ) { } 2.課題1を元に文字配列の2文字目以降の順序まで考慮した辞書式順序でソートを行うプログラムを作成せよ。関数名はlexicographic_sortとする。

  • このプログラムのポインタを配列に変換したいんですけど

    C言語初心者です。助けてください。 途中までがんばったのですがどうしてもできません。問題はこの構造体の*name→name[25],*email→email[30]に変換させたいのですが、そのまま変換すると左辺値が必要や移植性のないポインタ変換などのエラーが出てしまいます。どうすればいいですか?教えてください。あと関数getlineと構造体は変えないでください。(指定した部分は除く) このプログラムは名前、メールアドレス、年齢を保存していき-1を入力した時出力されるというものです。 よろしくお願いします。 入力例 10 hakata abc@・・・ 12 yokohama dfg@・・・ -1 -1 -1 出力例 -1 -1 -1 12 yokohama dfg@・・・ 10 hakata abc@・・・ #include <stdio.h> #include<stdlib.h> struct node { char *name; char *email; int age; struct node *next; } heap[100], *hp = heap; void getline(char *s,int n) { int c; while(--n>0&&((c=getchar())!=EOF && c!='\n')) *s++=c; *s='\0'; } char* dupstr(char* strg) { char* newstr; newstr=(char*)malloc(sizeof(char)*strlen(strg)); strcpy(newstr,strg); return newstr; } struct node *new(int n ,char* a, char* b) { hp->age=n; hp->email=a; hp->name=b; hp->next=NULL; return hp++; } struct node *add(struct node *p, struct node *q) { q->next=p; p=q; return p ; } void print_list(struct node *p) { while (p != NULL) { printf("%d ", p->age); printf("%s ", p->name); printf("%s ", p->email); p=p->next; } printf("\n"); } main() { int age,p; char buf[80],a[80],b[80],*email,*name; struct node *root=NULL; while(getline!=NULL) { getline(buf,sizeof(buf)); age=atoi(buf); getline(b,sizeof(b)); getline(a,sizeof(a)); email=dupstr(b); name=dupstr(a); root=add(root,new(age,email,name)); if(age==-1) break; } print_list(root); }

  • ポインタと配列

    次のソースで、結果表示でポインタを使いたいのですが、うまくいきません。1件しか表示されないのです。 ポインタの扱いがおかしいのだと思いますが、どうしたらよいでしょうか? #include <stdio.h> #include <string.h> int search(char key[256],FILE *fp,char *result[256][256]); main(void) { FILE *fp; int rep,n,i; char x[256],key[256],*result[256][256]; printf("検索キーワードを入力してください。\n" "キーワード>"); gets(key); if((fp=fopen("personal.txt","r"))==NULL) { printf("ファイルをオープンできません\n"); exit(1); } printf("=====検索結果=====\n"); n=search(key,fp,result); for(i=0;i<n;i++) { printf("%s\n",result[i]); } printf("検索結果:%d件です。\n",n); fclose(fp); } int search(char key[256],FILE *fp,char *result[256][256]) { int n=0; char *p,word[256],*name; while((p=fgets(word,256,fp))!=NULL) { if(strstr(word,key)!=NULL) { name=strtok(p," "); strcpy(result[n],name); n++; } } return n; } 実行すると、下の警告がでます。 illegal pointer combination(param)

  • 検索機能

    名簿管理システムとしてメンバの追加、メンバの削除、メンバリストを名前順(アルファベット昇順)で表示、メンバリストのファイル出力 引数としてファイルパスを指定することによるメンバ初期データの読込ができるプログラムを以下のように作成しました。 #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> typedef struct tagNode{ int no; char name[30]; struct tagNode *next; }Node; Node *ApndNode(Node *top, int no, char *name) { if(top == NULL){ top = (Node*)calloc(1, sizeof(Node)); top->no = no; strcpy(top->name, name); top->next = NULL; }else{ if(strcmp(top->name, name) > 0){ Node *p = (Node*)calloc(1, sizeof(Node)); p->no = no; strcpy(p->name, name); p->next = top; top = p; }else{ top->next = ApndNode(top->next, no, name); } } return top; } Node *DltNode(Node *top, int no, char *name) { if(top != NULL){ if(top->no == no && !strcmp(top->name, name)){ Node *p = top->next; free(top); top = p; }else{ top->next = DltNode(top->next, no, name); } } return top; } void PrintList(Node *top) { if(top != NULL){ printf("%-10d %s\n", top->no, top->name); PrintList(top->next); } } void PrintFile(Node *top) { FILE *fp; char file_name[256]; Node *p = top; printf("file name : "); scanf("%s", file_name); fp = fopen(file_name, "w"); if(!fp) return; while(p != NULL){ fprintf(fp, "%d %s\n", p->no, p->name); p = p->next;} fclose(fp); } void FreeList(Node *top) { while(top != NULL){ Node *p = top->next; free(top); top = p; } } int main(int argc, char *argv[]) { Node *top = NULL; int no, op; char name[30]; while ((op = getopt(argc, argv, "f:")) != -1){ switch (op){ case 'f': do{ FILE *fp = fopen(optarg, "r"); if(!fp) break; while(fscanf(fp, "%d%s", &no, name) == 2) top = ApndNode(top, no, name); fclose(fp); }while(0); } } while(1){ printf("--------command--------\n"); printf("1.Append\n2.Delete\n3.Show\n4.Save\n5.Quit\n"); printf("-----------------------\n"); printf("op : "); scanf("%d", &op); if(op == 5) break; switch(op){ case 1: printf("no : "); scanf("%d", &no); printf("name : "); scanf("%s", name); top = ApndNode(top, no, name); break; case 2: printf("no : "); scanf("%d", &no); printf("name : "); scanf("%s", name); top = DltNode(top, no, name); break; case 3: printf("=========list==========\n"); printf("<no> <name>\n"); PrintList(top); printf("=======================\n"); break; case 4: PrintFile(top); break; } } FreeList(top); return 0; } このプログラムに名前によって検索できる機能をつけるにはどのようにすればよいのでしょうか?教えてください。

  • 二分探索木

    下のプログラムはコンパイルはできたのですが、実行すると「セグメンテーション違反です」とでました。デバッガをしてみたら、 Program received signal SIGSEGV, Segmentation fault. 0x080483e8 in inorder (root=0x0) at nibun.c:12 12 inorder(root->llink); と表示されましたが解決方法が分かりません。どのように直せば、エラーを出さずに実行できるようになるか教えてください。 #include<stdio.h> #include<stdlib.h> typedef struct node *NodeP; typedef struct node { int data; NodeP llink, rlink; } Node; void inorder(NodeP root) { inorder(root->llink); printf(" %d", root->data); inorder(root->rlink); } NodeP newNode(int val) { NodeP newp = (NodeP) malloc (sizeof(Node)); newp->data = val; newp->llink = NULL; newp->rlink = NULL; return newp; } void insert(NodeP *root, int val){ NodeP curr,prev; if(*root == NULL) *root = newNode(val); else{ curr = *root; do{ prev = curr; if ( val < curr->data) curr = curr->llink; else if ( val > curr->data) curr = curr->rlink; else return; }while(curr!= NULL); if(val > prev->data){ prev->llink = newNode(val); } else{ prev->rlink = newNode(val); } } } NodeP createBSTree(void){ int i,n,val; NodeP root=NULL; printf("Number of Nodes:"); scanf("%d",&n); for (i=1;i<=n;i++){ printf("Node[%d]: ",i); scanf("%d",&val); insert(&root,val); } return root; } int main(){ NodeP root=NULL; root = createBSTree(); inorder(root); printf("\n"); return 0; }

  • C フォームから受け取った知をクッキーで発行 2

    前回 http://okwave.jp/qa/q7765400.html からあれこれしてフォームの値をクッキーに保存できるようになったのですが、バグが出てきました。 一、クッキーが存在しないとエラーが出る ニ、Deta1関数を使って文字列の分解を試みるもうまく分解されない この2つのバグを解決するにはどうしたら直せますか? ---以下ソース--- #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> char *nameset[2],*valueset[2]; char *nameset2[2],*valueset2[2]; int Deta1(char *a,int b); int Dcd(char *set,int a); void get_Form(void); void get_cookie(void); void set_cookie(void); int hen(char *buf, char *mae, char *ato); void Page(int mode); int main(void) { char *nameset[2],*valueset[2]; char *nameset2[2],*valueset2[2]; printf("Content-type: text/html\n"); get_Form(); set_cookie(); get_cookie(); printf("\n"); Page(0); } int Deta1(char *a,int b){ int i=0,cn=0; if(a[0]==NULL){ return(-1); } nameset[0]=a; while((a[++i]!=NULL)&&(i<b)){ /* 項目の分解 */ if(a[i]=='='){ a[i]=NULL; valueset[cn]=a+i+1; } /* データ項目で分解 */ else if(a[i]=='&'){ a[i]=NULL; cn++; nameset[cn]=a+i+1; } } return cn+1; } int Dcd(char *set,int a){ int i,j; char buf,*tmp; if(a==0){ return -1; } tmp=(char*)malloc(a); for(i=0,j=0;i<a;i++,j++){ if(set[i]=='+'){tmp[j]=' ';continue;} if(set[i]!='%'){tmp[j]=set[i];continue;} if(set[++i]>='A'){buf=set[i]-'A'+10;} else{buf=set[i]-'0';} buf*=16; if(set[++i]>='A'){buf+=set[i]-'A'+10;} else{buf+=set[i]-'0';} tmp[j]=buf; } for(i=0;i<j;i++){ set[i]=tmp[i]; } set[i]='\0'; free(tmp); return 0; } void get_Form(void){ int a=0; int i=0; char *chr=NULL; if ( getenv("CONTENT_LENGTH")!=NULL ){ a = atoi( getenv("CONTENT_LENGTH") ); } chr=(char *)malloc(a+1); scanf("%s",chr); chr[a] = '\0'; if (a==0){ return ; } int deta1=Deta1(chr,a); } void get_cookie(void){ int i=0,cn=0; int a=NULL; char *b; if( (getenv("HTTP_COOKIE"))!=NULL){ a=strlen(getenv("HTTP_COOKIE")); } if(a==NULL){ } b=getenv("HTTP_COOKIE"); while((b[++i]!=NULL)&&(i<a)){ if(b[i]=='='){ b[i]=NULL; nameset2[0]=b+i+1; } /* 項目の分解*/ if(b[i]=='-'){ b[i]=NULL; valueset2[cn]=b+i+1; } /*データ項目で分解*/ else if(b[i]=='&'){ b[i]=NULL; cn++; nameset2[cn]=b+i+1; } } for(i=0;i<cn+1;i++){ Dcd(nameset2[i],strlen(nameset2[i])); Dcd(valueset2[i],strlen(valueset2[i])); } } void set_cookie(void) { time_t timer; struct tm *tset; char expires[256]; char *name="sskchat"; int kikan=86400*90; char *set[2]; int i; for(i=0;i<2;i++){ set[i]=NULL; } for(i=0;i<2;i++){ set[i]=valueset[i]; } for(i=0;i<2;i++){ if(set[i]==NULL){ set[i]="no"; } } timer = time(NULL); timer += kikan; tset = gmtime(&timer); strftime(expires, 255, "%a, %d-%b-%Y %H:%M:%S GMT", tset); printf("Set-Cookie:%s=name-%s&mail-%s; expires=%s;\n",name,set[0],set[1],expires); } void Page(int mode){ FILE *fp; char *f1="!name!",*h1; char *f2="!mail!",*h2; if(valueset2[0]==NULL||strcmp("!name!",valueset2[0])==0){ h1=""; } else{ h1=valueset2[0]; } if(valueset2[1]==NULL||strcmp("!mail!",valueset2[1])==0){ h2=""; } else{ h2=valueset2[1]; } char buf[200]; char set[200]; fp = fopen("ren.html", "r+"); while( fgets( set, 200, fp ) != NULL ){ strcpy(buf,set); while(hen(buf, f1, h1)); while(hen(buf, f2, h2)); printf("%s", buf); } fclose(fp); } int hen(char *buf, char *mae, char *ato){ char *nw; size_t zen,go; zen = strlen(mae); go = strlen(ato); if(zen == 0 || (nw = strstr(buf, mae)) == NULL){ return 0; } memmove(nw + go, nw + zen, strlen(buf) - (nw + zen - buf ) + 1); memcpy(nw, ato, go); return 1; } ---ソースここまで--- ---ren.htmlの内容--- <form action="first.exe" method="post"> 名前:<input type="text" name="name" size="100" value="!name!"><br><br> メール:<input type="text" name="mail" size="100" value="!mail!"><br><br> 本文:<textarea name="text" cols="70" rows="10"></textarea><br><br> <input type="submit" value=" 送 信 "><br> </form>

    • ベストアンサー
    • CGI

専門家に質問してみよう