当前位置: 首页 > 笔记 > 正文

int main(int argc,char* argv[]) //int argc 参数个数 //char* […]

int main(int argc,char* argv[])

//int argc 参数个数
//char* argv[] 参数   字符型指针数组
//char *envp[]   微软自带 环境变量

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main(int argc,char* argv[])
  4. {
  5. for (int i =0; i < argc; i++)
  6. {
  7. puts(argv[i]);
  8. }
  9. system("pause");
  10. return 0;
  11. }

//程序名也算一个
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main(int argc,char* argv[],char *envp[])
  4. {
  5. int i = 0;
  6. while (*envp != NULL)
  7. {
  8. printf("%d:%srn",i,*envp);
  9. *envp++;
  10. i++;
  11. }
  12. system("pause");
  13. return 0;
  14. }
结果:
  1. 0:ALLUSERSPROFILE=C:ProgramData
  2. 1:APPDATA=C:Users韩AppDataRoaming
  3. 2:CommonProgramFiles=C:Program Files (x86)Common Files
  4. 3:CommonProgramFiles(x86)=C:Program Files (x86)Common Files
  5. 4:CommonProgramW6432=C:Program FilesCommon Files
  6. 5:COMPUTERNAME=CKDEBUG
  7. 6:ComSpec=C:WINDOWSsystem32cmd.exe
  8. 7:FPS_BROWSER_APP_PROFILE_STRING=Internet Explorer
  9. 8:FPS_BROWSER_USER_PROFILE_STRING=Default
  10. 9:HOMEDRIVE=C:
  11. 10:HOMEPATH=Users韩
  12. 11:LOCALAPPDATA=C:Users韩AppDataLocal
  13. 12:LOGONSERVER=\CKDEBUG
  14. 13:MSBuildLoadMicrosoftTargetsReadOnly=true
  15. 14:NUMBER_OF_PROCESSORS=4
  16. 15:OS=Windows_NT
  17. 16:PATH=C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32WindowsPowerShellv1.0;
  18. C:Program Files (x86)ATI TechnologiesATI.ACECore-Static;C:Program FilesMicrosoftWeb Platform Installer;
  19. C:Program Files (x86)Microsoft ASP.NETASP.NET Web Pagesv1.0;C:Program Files (x86)Windows Kits8.0Windows Performance Toolkit;
  20. C:Program FilesMicrosoft SQL Server110ToolsBinn;
  21. C:Program Files (x86)Windows LiveShared;
  22. C:Users韩AppDataLocalMicrosoftWindowsApps;;
  23. C:Program Files (x86)Microsoft Visual Studio 11.0;
  24. C:Program Files (x86)Microsoft Visual Studio 11.0VCbin
  25. 17:PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
  26. 18:PkgDefApplicationConfigFile=C:Users韩AppDataLocalMicrosoftVisualStudio11.0devenv.exe.config
  27. 19:PROCESSOR_ARCHITECTURE=x86
  28. 20:PROCESSOR_ARCHITEW6432=AMD64
  29. 21:PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 42 Stepping 7, GenuineIntel
  30. 22:PROCESSOR_LEVEL=6
  31. 23:PROCESSOR_REVISION=2a07
  32. 24:ProgramData=C:ProgramData
  33. 25:ProgramFiles=C:Program Files (x86)
  34. 26:ProgramFiles(x86)=C:Program Files (x86)
  35. 27:ProgramW6432=C:Program Files
  36. 28:PROMPT=$P$G
  37. 29:PSModulePath=C:Program FilesWindowsPowerShellModules;C:WINDOWSsystem32WindowsPowerShellv1.0Modules
  38. 30:PUBLIC=C:UsersPublic
  39. 31:SESSIONNAME=Console
  40. 32:SystemDrive=C:
  41. 33:SystemRoot=C:WINDOWS
  42. 34:TEMP=C:Users韩AppDataLocalTemp
  43. 35:TMP=C:Users韩AppDataLocalTemp
  44. 36:USERDOMAIN=CKDEBUG
  45. 37:USERDOMAIN_ROAMINGPROFILE=CKDEBUG
  46. 38:USERNAME=韩逸
  47. 39:USERPROFILE=C:Users韩
  48. 40:VisualStudioDir=C:Users韩DocumentsVisual Studio 2012
  49. 41:VisualStudioEdition=Microsoft Visual Studio Ultimate 2012
  50. 42:VisualStudioVersion=11.0
  51. 43:VS110COMNTOOLS=C:Program Files (x86)Microsoft Visual Studio 11.0Common7Tools
  52. 44:VSLANG=2052
  53. 45:windir=C:WINDOWS

本文固定链接: http://blog.050k.com/?p=399 | RotShell's Blog

11.课堂笔记_命令行参数:等您坐沙发呢!

发表评论

快捷键:Ctrl+Enter