我似乎无法在C下面生成随机数Ubuntu 12.04.
我写了以下代码:
#include <stdio.h>
#include <stdlib.h>
#include <curses.h>
int main (int argc,char* argv[])
{
int number;
clear();
number = rand() % 2; // want to get only 0 or 1
printf("%d",number);
getch();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我将文件命名为"test_gcc.c".
之后我编译它:
$ sudo gcc -o test_gcc test_gcc.c
Run Code Online (Sandbox Code Playgroud)
我收到以下消息:
/tmp/ccT0s12v.o: In function `main':
test_gcc.c:(.text+0xa): undefined reference to `stdscr'
test_gcc.c:(.text+0x12): undefined reference to `wclear'
test_gcc.c:(.text+0x44): undefined reference to `stdscr'
test_gcc.c:(.text+0x4c): undefined reference to `wgetch'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
有人能告诉我,我做错了什么吗? …