[問題] 一樣的程式linux上不能跑

看板C_and_CPP (C/C++)作者 (shyu4130)時間16年前 (2009/08/28 20:13), 編輯推噓2(204)
留言6則, 5人參與, 最新討論串1/1
在XP下用DEV C可以正常跑沒問題 但是換再LINUX用GCC complier時就不過了 以下是我程式碼的內容 #include <stdlib.h> #include <stdio.h> #include <string.h> struct dataBase{ char name[5]; }; main(){ dataBase start; printf("Enter name : \n"); scanf("%s",start.name); printf("%s",start.name); } -- 這程式碼沒什麼意義...只是先做些測試 沒想到第一關就卡關了 GCC上的錯誤訊息是 hello.c: In function 「main」: hello.c:10: 錯誤: 「dataBase」 未宣告 (在此函式內第一次使用) hello.c:10: 錯誤: (即使在一個函式內多次出現,每個未宣告的識別碼在其 hello.c:10: 錯誤: 所在的函式內只報告一次。) hello.c:10: 錯誤: expected 「;」 before 「start」 hello.c:13: 錯誤: 「start」 未宣告 (在此函式內第一次使用) 我用的DEV-C版本為4.9.9.2 GCC版本4.3.3 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.121.106.3 ※ 編輯: shyu4130 來自: 59.121.106.3 (08/28 20:14)

08/28 20:15, , 1F
struct dataBase start;
08/28 20:15, 1F

08/28 20:16, , 2F
struct dataBase start; 試試看
08/28 20:16, 2F

08/28 20:19, , 3F
宣告前面不用加struct是C++用法@@
08/28 20:19, 3F

08/28 20:19, , 4F
謝謝! 問題解決了 感謝兩位
08/28 20:19, 4F

08/28 20:20, , 5F
原來如此 感謝3F DEV C用習慣的下場...
08/28 20:20, 5F

08/30 14:46, , 6F
你少了 typedef的宣告
08/30 14:46, 6F
文章代碼(AID): #1Abye0y4 (C_and_CPP)
文章代碼(AID): #1Abye0y4 (C_and_CPP)