推介:| 英語課程 | Causeway Bay order food | 職業英語 | 化妝課程 | Wedding Photography | 天窗卷布更換維修 |

發新話題
打印

想請教一下C語言格式化的輸入與輸出

想請教一下C語言格式化的輸入與輸出

今次有兩個C語言有關格式化的輸入與輸出有問題, 請看以下程式碼:
/* porg4_17.c, 讀取輸入緩衝區內殘留的資料 */
#include<stdio.h>
#include<stdlib.h>
int man(void)
{
    int num;
    char str[10];
   
    printf("請輸入一個整數:");
    scanf("%d", &num);
    printf("num=%d\n", num);
   
    printf("請輸入一個字串:");
    scanf("%s", str);
    printf("str=%s\n", str);
   
    system("pause");
    return 0;
}
     
這個程式個人覺得沒有什麼問題, 但不知何故竟然輸出的是以下的對話:
  [Linker error] undefined reference to `WinMain@16'

而另外一個程式碼是這樣的:
/* prog4_16.c, 利用scanf()函數讀取數值 */
#include<stdio.h>
#include<stdlib.h>
int main(void)
(
     int num;
     
     printf("請輸入一個整數:");
     scanf("%d", &num);
     printf("num=%d\n", num);
     
     system("pause");
     return 0;
}      

也是不能執行, 因為它輸出以下的對話:
8 F:\C\prog4_16.c parse error before "printf"
8 F:\C\prog4_16.c `main' declared as function returning a function
9 F:\C\prog4_16.c parse error before string constant
9 F:\C\prog4_16.c [Warning] data definition has no type or storage class
10 F:\C\prog4_16.c parse error before string constant
10 F:\C\prog4_16.c [Warning] conflicting types for built-in function `printf'
10 F:\C\prog4_16.c [Warning] data definition has no type or storage class
12 F:\C\prog4_16.c parse error before string constant
12 F:\C\prog4_16.c [Warning] data definition has no type or storage class

究竟出了什麼問題呢??


相關搜索目錄: 語言

TOP

回復 1# 的帖子

1.  porg4_17.c中的man(void)應該是main(void);
     而且需要include stdio.h
2.  prog4_16.c中, main(void)後的應該是curly brace.
IT代工/鎗手一名!
小弟並唔平, 但絕唔係貴!

TOP

認同.........應該好似樓上咁講..xd

TOP

那要看你用的什么编译器了....
现在有很多小型编译器是不全的
你把MAIN函数重写几次...
像什么MAIN()
void main()
int main()
都试下..我也刚学
总是这样那样不对
也不知道对不对...呵呵

TOP

In "porg4_17.c", seem your compiler try to compiler your code into windows program instead of
a console program. Try to add "/link /system:console" in your compile flags, I assume you are
using visual c compiler.

TOP

ai...........................

TOP

發新話題


重要聲明:本討論區是以即時上載留言的方式運作,本網站對所有留言的真實性、完整性及立場等,不負任何法律責任。而一切留言之言論只代表留言者個人意見,並非本網站之立場,用戶不應信賴內容,並應自行判斷內容之真實性。於有關情形下,用戶應尋求專業意見(如涉及醫療、法律或投資等問題)。由於本討論區受到「即時上載留言」運作方式所規限,故不能完全監察所有留言,若讀者發現有留言出現問題,請聯絡我們。本討論區有權刪除任何留言及拒絕任何人士上載留言,同時亦有不刪除留言的權利。切勿撰寫粗言穢語、誹謗、渲染色情暴力或人身攻擊的言論,敬請自律。本網站保留一切法律權利。


Copyright 1997- Xocat. All Right Reserved.