gpt4 book ai didi

c - 在程序中包含可选输入?

转载 作者:行者123 更新时间:2023-11-30 15:24:49 25 4
gpt4 key购买 nike

我想知道是否有办法在我的代码中创建可选输入?我正在编写一个代码,它将打印出 480x480 纯文本图像的 RGB 值。该代码应该允许我以任意顺序输入 4 个可选值 --rx将每个像素的红色分量的 sin 缩放两倍 x,-gx与 -r 相同,除了绿色组件-bx做同样的事情,但是用蓝色-sn指定整数 n 的图像边长。

这是我的代码:

int* arrayfill()
{
int* bmult;
bmult = malloc(sizeof(int)*480*480);
for (int y = 0; y < 480; y++) {
for (int x = 0; x < 480; x++) {
bmult[x + y*480] = (128*sin( sqrt(pow(x-240,2) + pow(y-240,2)))+128);
if (0 <= (bmult[x + y*480]) || (bmult[x + y*480]) >= 255) {
continue;
}
else {
fprintf(stderr, "The scale must result in a b value between 0 & 255");
break;
}
}}
return bmult;
}

int main(int argc, char* argv[])
{
int* newarray = arrayfill();
printf(" P3\n");
printf("480 480\n");
printf("255\n");
for (int count = 0; count < 480*480; count++) {
printf("0, 0, %d\n", newarray[count]);
}
}

最佳答案

您可以使用getopt(和getopt_long)。

The getopt and getopt_long functions automate some of the chore involved in parsing typical unix command line options.

参见http://www.gnu.org/software/libc/manual/html_node/Getopt.html有关用法和示例。

关于c - 在程序中包含可选输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28206772/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com