2017-02-25 53 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 –