推介:| Web Hosting | 外賣系統 | Server colocation | Web Shop System | Makeup course |

查看完整版本: 想請教一下C語言格式化的輸入與輸出

花之慶次 2010-3-12 16:22

想請教一下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

究竟出了什麼問題呢??

jayzhou_2046 2010-3-12 22:06

回復 1# 的帖子

1.  porg4_17.c中的man(void)應該是main(void);
     而且需要include stdio.h
2.  prog4_16.c中, main(void)後的應該是curly brace.

dou 2010-3-24 19:00

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

sevendoors 2010-4-12 10:52

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

issa 2010-4-17 15:56

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.

cyrus_911hk 2010-4-17 17:55

ai...........................
頁: [1]
查看完整版本: 想請教一下C語言格式化的輸入與輸出