fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define S 100
  5. #define N 1000
  6.  
  7. int main(int argc, char *argv[]) {
  8. argc = 10;
  9. char out[S];
  10. char buf[N];
  11. char msg[] = "Welcome to the argument echoing program\n";
  12. int len = 0;
  13. buf[0] = '\0';
  14. printf(msg);
  15. while (argc) {
  16. //sprintf(out, "argument %d is %s\n", argc-1, argv[argc-1]);
  17. snprintf(out, S, "argument %d is %s\n", argc-1, argv[argc-1]);
  18. argc--;
  19. strncat(buf,out,sizeof(buf)-len-1);
  20. printf("%s\n",buf);
  21. len = strlen(buf);
  22. //printf("%d\n", len);
  23. }
  24. printf("hi1\n");
  25. //printf("%s",buf);
  26. printf(buf);
  27. printf("hi2\n");
  28. return 0;
  29. }
Success #stdin #stdout 0s 5272KB
stdin
Standard input is empty
stdout
Welcome to the argument echoing program
argument 9 is PATH=/usr/local/bin:/usr/bin:/bin

argument 9 is PATH=/usr/local/bin:/usr/bin:/bin
argument 8 is SHLVL=0

argument 9 is PATH=/usr/local/bin:/usr/bin:/bin
argument 8 is SHLVL=0
argument 7 is WORKSPACE=/tmp/

argument 9 is PATH=/usr/local/bin:/usr/bin:/bin
argument 8 is SHLVL=0
argument 7 is WORKSPACE=/tmp/
argument 6 is TMPDIR=/tmp/FeZsmk

argument 9 is PATH=/usr/local/bin:/usr/bin:/bin
argument 8 is SHLVL=0
argument 7 is WORKSPACE=/tmp/
argument 6 is TMPDIR=/tmp/FeZsmk
argument 5 is LANG=en_US.UTF-8

argument 9 is PATH=/usr/local/bin:/usr/bin:/bin
argument 8 is SHLVL=0
argument 7 is WORKSPACE=/tmp/
argument 6 is TMPDIR=/tmp/FeZsmk
argument 5 is LANG=en_US.UTF-8
argument 4 is HOME=/home/PgoT4k

argument 9 is PATH=/usr/local/bin:/usr/bin:/bin
argument 8 is SHLVL=0
argument 7 is WORKSPACE=/tmp/
argument 6 is TMPDIR=/tmp/FeZsmk
argument 5 is LANG=en_US.UTF-8
argument 4 is HOME=/home/PgoT4k
argument 3 is TMPDIR_GLOBAL=/tmp/

argument 9 is PATH=/usr/local/bin:/usr/bin:/bin
argument 8 is SHLVL=0
argument 7 is WORKSPACE=/tmp/
argument 6 is TMPDIR=/tmp/FeZsmk
argument 5 is LANG=en_US.UTF-8
argument 4 is HOME=/home/PgoT4k
argument 3 is TMPDIR_GLOBAL=/tmp/
argument 2 is PWD=/home/PgoT4k

argument 9 is PATH=/usr/local/bin:/usr/bin:/bin
argument 8 is SHLVL=0
argument 7 is WORKSPACE=/tmp/
argument 6 is TMPDIR=/tmp/FeZsmk
argument 5 is LANG=en_US.UTF-8
argument 4 is HOME=/home/PgoT4k
argument 3 is TMPDIR_GLOBAL=/tmp/
argument 2 is PWD=/home/PgoT4k
argument 1 is (null)

argument 9 is PATH=/usr/local/bin:/usr/bin:/bin
argument 8 is SHLVL=0
argument 7 is WORKSPACE=/tmp/
argument 6 is TMPDIR=/tmp/FeZsmk
argument 5 is LANG=en_US.UTF-8
argument 4 is HOME=/home/PgoT4k
argument 3 is TMPDIR_GLOBAL=/tmp/
argument 2 is PWD=/home/PgoT4k
argument 1 is (null)
argument 0 is ./prog

hi1
argument 9 is PATH=/usr/local/bin:/usr/bin:/bin
argument 8 is SHLVL=0
argument 7 is WORKSPACE=/tmp/
argument 6 is TMPDIR=/tmp/FeZsmk
argument 5 is LANG=en_US.UTF-8
argument 4 is HOME=/home/PgoT4k
argument 3 is TMPDIR_GLOBAL=/tmp/
argument 2 is PWD=/home/PgoT4k
argument 1 is (null)
argument 0 is ./prog
hi2