[問題] 有關結構陣列的問題

看板C_and_CPP作者 (大戰槍)時間14年前 (2009/08/19 11:06), 編輯推噓2(206)
留言8則, 2人參與, 最新討論串1/1
問題是這樣的: 輸入三個人的名字與成績 以結構陣列建立之 接著把三個人的成績開根號乘以10的方式計算 最後列印每位同學調整前與調整後的分數 以下是我寫的程式碼 #include <stdio.h> #include <stdlib.h> struct score{ char *name; int score; }; void before(struct score *); void after(struct score *); int main(void) { struct score st[3]; int i,j,k; for(i = 0 ; i < 3;i++) { scanf("%s",&st[i].name); } for(j = 0 ; j < 3;j++) { scanf("%d",&st[j].score); } before(st); after(st); return 0; } void before(struct score *s) { int k; for(k = 0 ; k < 3;k++) printf("%-10s 's %3d",s[k].name,s[k].score); } void after(struct score *t) { int i,j; printf("After change is\n"); for(i = 0 ; i < 3;i++) { t[i].score = sqrt(t[i].score)*10; } for(j = 0 ; j < 3;j++) { printf("%-10s 's %3d",t[j].name,t[j].score); } } 這樣子執行會出錯 可是不知道問題在哪 有請板上的大大幫幫忙~~謝謝摟 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.43.184.139

08/19 11:24, , 1F
拜託"執行會出錯"是怎樣錯請講清楚, compile error??執
08/19 11:24, 1F

08/19 11:24, , 2F
name 沒有初始化 new char[] or (char)malloc( ) ??
08/19 11:24, 2F

08/19 11:25, , 3F
行時會當掉??結果不對(那結果為何)??必要時連開發環境都
08/19 11:25, 3F

08/19 11:25, , 4F
要說....~_~
08/19 11:25, 4F

08/19 11:25, , 5F
(char*)
08/19 11:25, 5F

08/19 11:26, , 6F
小弟我眼前看到的, sqrt應該在math.h裡不過似乎沒有被
08/19 11:26, 6F

08/19 11:26, , 7F
include到....@_@"
08/19 11:26, 7F

08/19 11:31, , 8F
g大眼睛好利....:)
08/19 11:31, 8F
文章代碼(AID): #1AYsmYr- (C_and_CPP)