2017-02-25 87 views
-4

我試圖在使用「scanf」函數將其作爲輸入之後使用一個數字。例如,如果我輸入2我想知道如何在我的代碼的後期階段使用它(也許調用另一個函數)。掃描已打印的值

#include<stdio.h> 
int main(){ 

    int Input; 
    scanf("%d",Input); 
    printf("%d", Input); 
    //here is the place where I want to use the Input 

    return 0; 
} 

在代碼示例中,在命令printf之後,我應該如何進一步開發代碼。

+1

如果這個程序有效,你已經把這個號碼送到'printf'。只需將其提供給不同的功能。 – jxh

+2

對'scanf'的調用是錯誤的。您必須將一個指針傳遞給'Input',而不是'Input'的值。 – DyZ

+1

我懷疑這是一個[XY](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)問題,你究竟在做什麼? – George

回答

0

林不知道這是否回答你的問題。你不必打印價值來使用它。你可以在你從scanf中取出它之後隨便使用它。

#include<stdio.h> 

int inc(int input) { 
    int val = input + 1; 
    return val; 
} 

int main(){ 

    int Input; 
    scanf("%d",&Input); //dont forget & 
    //now you have the input saved, do anything you want with Input 
    printf("%d",Input); // you can print the value you scanned 
    int out = inc(Input); //you can put it in a new function 
    printf("%d %d",Input,out); //you can output it again, "printf" is also another function 

    return 0; 
} 
+1

那就是我想要的東西..感謝幫助我..我是新的cording ... :) @AyonNahiyan –

+0

歡迎您! :D @ roch.p –