argtest.c 826 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Program to test argument passing: it displays the argc and all
  3. * of argv, and then exits.
  4. *
  5. * Intended for the basic system calls assignment. This may help
  6. * debugging the argument handling of execv().
  7. */
  8. #include <stdio.h>
  9. int
  10. main(int argc, char *argv[])
  11. {
  12. const char *tmp;
  13. int i;
  14. printf("argc : %d\n", argc);
  15. printf("&tmp : %p\n", &tmp);
  16. printf("&i : %p\n", &i);
  17. printf("&argc : %p\n", &argc);
  18. printf("&argv : %p\n", &argv);
  19. printf("argv : %p\n", argv);
  20. printf("\n");
  21. for (i=0; i<=argc; i++) {
  22. printf("&argv[%d] : %p\n", i, &argv[i]);
  23. }
  24. printf("\n");
  25. for (i=0; i<=argc; i++) {
  26. printf("argv[%d] : %p\n", i, argv[i]);
  27. }
  28. printf("\n");
  29. for (i=0; i<=argc; i++) {
  30. tmp = argv[i];
  31. if (tmp == NULL) {
  32. tmp = "[NULL]";
  33. }
  34. printf("argv[%d] -> %s\n", i, tmp);
  35. }
  36. return 0;
  37. }