質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C

C言語は、1972年にAT&Tベル研究所の、デニス・リッチーが主体となって作成したプログラミング言語です。 B言語の後継言語として開発されたことからC言語と命名。そのため、表記法などはB言語やALGOLに近いとされています。 Cの拡張版であるC++言語とともに、現在世界中でもっとも普及されているプログラミング言語です。

Q&A

解決済

2回答

1170閲覧

undefined reference to~によるエラーの解決法

yuto_jake

総合スコア42

C

C言語は、1972年にAT&Tベル研究所の、デニス・リッチーが主体となって作成したプログラミング言語です。 B言語の後継言語として開発されたことからC言語と命名。そのため、表記法などはB言語やALGOLに近いとされています。 Cの拡張版であるC++言語とともに、現在世界中でもっとも普及されているプログラミング言語です。

0グッド

0クリップ

投稿2022/05/24 06:29

C言語で、タスク情報を記録できるシステムを作成しています。以下のソースコードから実行しようとすると
C:\Users\AppData\Local\Temp\ccQhtmBp.o:qq.c:(.text+0x3c): undefined reference to edittask' C:\Users\\AppData\Local\Temp\ccQhtmBp.o:qq.c:(.text+0x43): undefined reference to deletetask'
のエラーが表示されプログラムがうまく実行できません。
エラーの原因及び修正箇所の提示をご教授していただけると幸いです。

c

1#include <stdio.h> 2 3void addtask(); 4void viewtask(); 5void edittask(); 6void deletetask(); 7char menu(); 8 9int main() { 10 char selection ; 11 do { 12 selection = menu(); 13 switch(selection) { 14 case '1': addtask(); break; 15 case '2': viewtask(); break; 16 case '3': edittask(); break; 17 case '4': deletetask(); break; 18 case '5': break; 19 default: printf("Invalid option"); 20 } 21 }while(selection != '1'); 22 return 0; 23} 24 25char menu() { 26 char option; 27 printf("\n1) Add New Task"); 28 printf("\n2) View Task"); 29 printf("\n3) Edit Task"); 30 printf("\n4) Delete Task"); 31 printf("\n5) Exit"); 32 printf("\nEnter option: "); 33 scanf("%c[^\n]", &option); 34 return option; 35} 36 37void addtask( ){ 38 int utask, duedate, status, category, note; 39 printf("\n\n\t\t---------------------------------\n"); 40 printf("\t\t* Welcome to Add Task Menu! *"); 41 printf("\n\t\t---------------------------------\n\n"); 42 43 FILE * f = fopen("task.txt", "r+"); 44 if(f == NULL) 45 f = fopen("task.txt", "w"); 46 else { 47 fseek(f, 0, SEEK_END); 48 printf("\nEnter your Task name:"); 49 scanf("%s", &utask); 50 printf("\nEnter your Task due date[yyyy-mm-dd]: "); 51 scanf("%d", &duedate); 52 printf("\nENTER progress percentage[0.00~100]:"); 53 scanf("%f", &status); 54 printf("\nEnter category: "); 55 scanf("%s", &category); 56 printf("\nEnter Note: "); 57 scanf("%s", &note); 58 fprintf(f,"%s %d %f %s %s\n", utask, duedate, status, category, note); 59 } 60 fclose(f); 61} 62 63void viewtask(){ 64 int na, d, s, c, no; 65 printf("\nThis is Your task details"); 66 FILE * f = fopen("task.txt", "r"); 67 while(fscanf(f,"%s",&na) != EOF){ 68 fscanf(f,"%d",&d); 69 fscanf(f,"%f",&s); 70 fscanf(f,"%s",&c); 71 fscanf(f,"%s",&no); 72 printf("\nYour Task: %s \t Task duedate: %d \t Task progression: %f \t Task category: %s \t Task note: %s",na, d, s, c, no); 73 } 74 fclose(f); 75} 76 77void update() { 78 int utask, d, s, c, no, na; 79 FILE * f = fopen("task.txt", "r"); 80 FILE * ft = fopen("tmp.txt", "w"); 81 printf("\nthis is edit task"); //変更 82 printf("\nEnter your task:"); 83 scanf("%s", &utask); 84 while(fscanf(f,"%s",&na) != EOF){ 85 fscanf(f,"%d",&d); 86 fscanf(f,"%f",&s); 87 fscanf(f,"%s",&c); 88 fscanf(f,"%s",&no); 89 if(na == utask){ 90 printf("\nUpdating >> your task: %s \t duedate: %d \t stasus: %f \t category: %s \t note: %s", na, d, s, c, no); 91 printf("\nEnter new duedate:"); 92 scanf("%d", &d); 93 printf("\nEnter new progression:"); 94 scanf("%f", &s); 95 printf("\nEnter new category:"); 96 scanf("%s", &c); 97 printf("\nEnter new note:"); 98 scanf("%s", &no); 99 } 100 fprintf(ft,"%s %d %f %s %s\n", na, d, s, c, no); 101 } 102 fclose(ft); 103 fclose(f); 104 remove("task.txt"); 105 rename("tmp.txt", "task.txt"); 106} 107 108void delete() { 109 int utask, d, s, c, no, na; 110 FILE * f = fopen("data.txt", "r"); 111 FILE * ft = fopen("tmp.txt", "w"); 112 printf("\nthis is delete record"); 113 printf("\nEnter utask:"); 114 scanf("%d", &utask); 115 while(fscanf(f,"%s",&na) != EOF){ 116 fscanf(f,"%d",&d); 117 fscanf(f,"%f",&s); 118 fscanf(f,"%s",&c); 119 fscanf(f,"%s",&no); 120 if(na == utask){ 121 printf("\nDelete -> your task: %s \t duedate: %d \t progression: %f \t category: %s \t note: %s", na, d, s, c, no); 122 continue; 123 } 124 fprintf(ft,"%s %d %f %s %s\n", na, d, s, c, no); 125 } 126 fclose(ft); 127 fclose(f); 128 remove("task.txt"); 129 rename("tmp.txt", "task.txt"); 130} 131

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Zuishin

2022/05/24 06:47

update() と delete() がそれぞれ edittask() と deletetask() の間違いだと思います。 それぞれの関数名を検索して漏れなく修正し、解決したのであれば自分で回答してそれをベストアンサーに選んでください。
yuto_jake

2022/05/24 09:09

Zuishinさん、コメントありがとうございます。 おっしゃる通りで、update() と delete() がそれぞれ edittask() と deletetask() の間違いでした。。 ご回答ありがとうございます。
Zuishin

2022/05/24 09:09

解決したのであれば、自分で回答してそれをベストアンサーに選んで質問を閉じてください。
guest

回答2

0

自己解決

c

1#include <stdio.h> 2 3void addtask(); 4void viewtask(); 5void edittask(); 6void deletetask(); 7char menu(); 8 9int main() { 10 char selection ; 11 do { 12 selection = menu(); 13 switch(selection) { 14 case '1': addtask(); break; 15 case '2': viewtask(); break; 16 case '3': edittask(); break; 17 case '4': deletetask(); break; 18 case '5': break; 19 default: printf("Invalid option"); 20 } 21 }while(selection != '1'); 22 return 0; 23} 24 25char menu() { 26 char option; 27 printf("\n1) Add New Task"); 28 printf("\n2) View Task"); 29 printf("\n3) Edit Task"); 30 printf("\n4) Delete Task"); 31 printf("\n5) Exit"); 32 printf("\nEnter option: "); 33 scanf("%c[^\n]", &option); 34 return option; 35} 36 37void addtask( ){ 38 int utask, duedate, status, category, note; 39 printf("\n\n\t\t---------------------------------\n"); 40 printf("\t\t* Welcome to Add Task Menu! *"); 41 printf("\n\t\t---------------------------------\n\n"); 42 43 FILE * f = fopen("task.txt", "r+"); 44 if(f == NULL) 45 f = fopen("task.txt", "w"); 46 else { 47 fseek(f, 0, SEEK_END); 48 printf("\nEnter your Task name:"); 49 scanf("%s", &utask); 50 printf("\nEnter your Task due date[yyyy-mm-dd]: "); 51 scanf("%d", &duedate); 52 printf("\nENTER progress percentage[0.00~100]:"); 53 scanf("%f", &status); 54 printf("\nEnter category: "); 55 scanf("%s", &category); 56 printf("\nEnter Note: "); 57 scanf("%s", &note); 58 fprintf(f,"%s %d %f %s %s\n", utask, duedate, status, category, note); 59 } 60 fclose(f); 61} 62 63void viewtask(){ 64 int na, d, s, c, no; 65 printf("\nThis is Your task details"); 66 FILE * f = fopen("task.txt", "r"); 67 while(fscanf(f,"%s",&na) != EOF){ 68 fscanf(f,"%d",&d); 69 fscanf(f,"%f",&s); 70 fscanf(f,"%s",&c); 71 fscanf(f,"%s",&no); 72 printf("\nYour Task: %s \t Task duedate: %d \t Task progression: %f \t Task category: %s \t Task note: %s",na, d, s, c, no); 73 } 74 fclose(f); 75} 76 77void edittask() { 78 int utask, d, s, c, no, na; 79 FILE * f = fopen("task.txt", "r"); 80 FILE * ft = fopen("tmp.txt", "w"); 81 printf("\nthis is edit task"); //変更 82 printf("\nEnter your task:"); 83 scanf("%s", &utask); 84 while(fscanf(f,"%s",&na) != EOF){ 85 fscanf(f,"%d",&d); 86 fscanf(f,"%f",&s); 87 fscanf(f,"%s",&c); 88 fscanf(f,"%s",&no); 89 if(na == utask){ 90 printf("\nUpdating >> your task: %s \t duedate: %d \t stasus: %f \t category: %s \t note: %s", na, d, s, c, no); 91 printf("\nEnter new duedate:"); 92 scanf("%d", &d); 93 printf("\nEnter new progression:"); 94 scanf("%f", &s); 95 printf("\nEnter new category:"); 96 scanf("%s", &c); 97 printf("\nEnter new note:"); 98 scanf("%s", &no); 99 } 100 fprintf(ft,"%s %d %f %s %s\n", na, d, s, c, no); 101 } 102 fclose(ft); 103 fclose(f); 104 remove("task.txt"); 105 rename("tmp.txt", "task.txt"); 106} 107 108void deletetask() { 109 int utask, d, s, c, no, na; 110 FILE * f = fopen("data.txt", "r"); 111 FILE * ft = fopen("tmp.txt", "w"); 112 printf("\nthis is delete record"); 113 printf("\nEnter utask:"); 114 scanf("%d", &utask); 115 while(fscanf(f,"%s",&na) != EOF){ 116 fscanf(f,"%d",&d); 117 fscanf(f,"%f",&s); 118 fscanf(f,"%s",&c); 119 fscanf(f,"%s",&no); 120 if(na == utask){ 121 printf("\nDelete -> your task: %s \t duedate: %d \t progression: %f \t category: %s \t note: %s", na, d, s, c, no); 122 continue; 123 } 124 fprintf(ft,"%s %d %f %s %s\n", na, d, s, c, no); 125 } 126 fclose(ft); 127 fclose(f); 128 remove("task.txt"); 129 rename("tmp.txt", "task.txt"); 130} 131

関数設定を間違えていました。

投稿2022/05/24 09:10

yuto_jake

総合スコア42

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

edittaskと deletetaskがどこにもない、というエラーです。
それらの関数の本体はどこにあるんでしょうか

投稿2022/05/24 06:34

y_waiwai

総合スコア87774

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

yuto_jake

2022/05/24 09:09

y_waiwaiさん、コメントありがとうございます。 コード内のupdate() と delete() がそれぞれ edittask() と deletetask() の間違いでした。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問