我正在创建一个python脚本,从这里的男性名字列表中随机选择1000个名字:http://www.census.gov/genealogy/www/data/1990surnames/names_files.html
这样做很好,花花公子,但我希望它能根据人口普查文本文件(第二栏)提供的概率列选择名称.
在过去的几个小时里,我一直试图围绕这一点,但我没有取得任何实际进展,甚至寻找其他答案.
任何人都可以帮助我或指出我正确的方向吗?提前致谢 :)
我想在这个问题前面说我是C的新手并因此很糟糕,所以我提前为任何明显的错误或糟糕的风格道歉.此外,我不知道如何在向您展示我的代码之前介绍问题,所以这里是:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int MAX_INPUT_SIZE = 200;
volatile int running = 1;
while (running)
{
char input[MAX_INPUT_SIZE];
char *tokens[100];
const char *cmds[] = { "wait", "pwd", "cd", "exit" };
char *cmdargs[100];
printf("shell> ");
fgets(input, MAX_INPUT_SIZE, stdin);
// remove newline character at end
int nl = strlen(input) - 1;
if (input[nl] == '\n')
{
input[nl] = '\0';
}
// tokenize input string, put each token into an array
char *space;
space = strtok(input, " …
Run Code Online (Sandbox Code Playgroud) 我写的程序需要删除&符号,如果它是字符串的最后一个字符.例如,如果char* str
包含"firefox&"
,那么我需要删除&符号以便str
包含"firefox"
.有谁知道如何做到这一点?