【问题标题】:Warning when compiling, with a program that 'waits/delays'编译时发出警告,程序“等待/延迟”
【发布时间】:2017-10-31 04:47:53
【问题描述】:

我正在尝试提示用户输入他们希望程序等待的时间。但是,当我编译程序时,它会产生以下警告:

warning: assignment makes integer from pointer without a cast

警告引用以下行:

y = sleeptime;

我不太明白这一点,因为我的程序中没有任何指针。

提前致谢。

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>

int sleeptime(void)
{
    int x;
    x = 0;
    printf("How long would you like to wait?\n");
    scanf("%d", &x);

    return x;
}

int main(void)
{
    int y;    
    y = 0;
    y = sleeptime;
    sleep(y);

    return 0;
}

【问题讨论】:

  • 如何在 C 中调用函数?也许您需要几个good beginners books 才能阅读?
  • 啊,我才意识到错误。是的,我绝对可以更好地建立我的基础。谢谢!

标签: c warnings sleep


【解决方案1】:

只是改变

y = sleeptime;

y = sleeptime();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-23
    • 1970-01-01
    • 2015-08-10
    • 1970-01-01
    • 1970-01-01
    • 2012-05-27
    • 1970-01-01
    相关资源
    最近更新 更多