Advertisement
userxbw

argv array based C

Aug 14th, 2022
900
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main (int argc, char **argv){
  5. if (argc<2){
  6.  printf("need more arguments\n");
  7.  exit(1);
  8. }
  9. printf("argc = %d it is a zero based\n"
  10.        "value to deal with argv\n"
  11.        "which is a 2D char array\n",
  12.         argc);
  13. printf("argv 0 %s= the program name\n",
  14. argv[0]);
  15. for(int i=0;i<argc;i++){
  16.  printf("%s\n",argv[i]);}
  17. int len= strlen(argv[0]);
  18. for(int i;i<len;i++){
  19.    printf("argv[0][%d]=%c\n ",
  20.    i,argv[0][i]); }
  21.  printf("argv 1 %s = Is first argument\n"
  22.         "off the line\n",argv[1]);
  23. len=strlen(argv[1]);
  24. for(int i;i<len;i++)
  25.  printf("argv[0][%d]=%c\n ",i,argv[1][i]);
  26.  
  27. printf("\nSo on and so fourth\n"
  28.        "because argv is too an\n"
  29.        "array. A 2D array of type\n"
  30.        "char\n");
  31. return 0;
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement