getopt.c

来自「基于稀疏网络的精选机器学习模型」· C语言 代码 · 共 45 行

C
45
字号
/*************************************************************************//*                                                                       *//*  This file is included in case your version of Unix doesn't include   *//*  the getopt utility.  If it does, discard this file and amend the     *//*  Makefile accordingly.                                                *//*                                                                       *//*  There is no copyright on this file.                                  *//*                                                                       *//*************************************************************************/#include <stdio.h>int optind = 1;char* optarg;char getopt(int Argc, char** Argv, char* Str){  char Optchar;  char* Option;  if ( optind >= Argc ) return EOF;  Option = Argv[optind++];  if ( *Option++ != '-' ) return '?';  Optchar = *Option++;  while ( *Str && *Str != Optchar ) Str++;  if ( ! *Str ) return '?';  if ( *++Str == ':' )  {    if ( *Option ) optarg = Option;    else      if ( optind < Argc ) optarg = Argv[optind++];      else Optchar = '?';  }  return Optchar;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?