例如,创建了一个hello.c文本,在文本中写入
#include <stdio.h>
int main(void)
{
printf(“hello world!!”)
return 0
}
然后在终端输入
$ gcc –o hello hello.c
$ /tmp/hello
注:hello.c文件放在/tmp目录下,通过gcc -o hello hello.c命令生成一个hello文件,它是一个可执行文件,然后直接执行,就可以运行该程序了。
#include <stdio.h>#include <unistd.h>
int main (int argc, char **argv)
{
int oc/*选项字符 */
char *b_opt_arg /*选项参数字串 */
while((oc = getopt(argc, argv, "n:")) != -1)
{
switch(oc)
{
case 'n':
b_opt_arg = optarg
break
}
}
printf("hello world : %s\n",b_opt_arg)
return 0
}
运行结果:
# ./hello -n 3
hello world : 3
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)