示例
//Visual Studio中加上这句才可以使用scanf()
//否则只能使用scanf_s()
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define NUM 5
//argc: 参数个数 argv[]: 参数数组
int main(int argc, char *argv[])
{
char ch_arr[NUM][8] = { "小东", "小明","小李","小王","小红" };
srand((unsigned)time(NULL));// 初始化随机数
for (int i = 0; i < 10; i++) {
int r = rand() % NUM;
printf("[%d] %s\n", r, ch_arr[r]);
}
system("pause");
return 0;
}
运行测试
注意:必须确保窗口的代码页设置的是中文