Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 8th, 2012  |  syntax: None  |  size: 0.49 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. pass char array as argument
  2. #include <stdio.h>
  3.  
  4. int main ( int argc, char *argv[] )
  5. {
  6.     char *array= argv[0];
  7.     foo(*array);
  8. }
  9.  
  10. void foo( char *array)
  11. // notice the return type - it's a pointer
  12. {
  13.     printf(array);
  14. }
  15.        
  16. foo(array);
  17.        
  18. printf("%s", array);
  19.        
  20. #include <stdio.h>
  21.  
  22. void foo(char *array)
  23. {
  24.     printf("%s", array);
  25. }
  26.  
  27. int main ( int argc, char *argv[] )
  28. {
  29.     // TODO:  make sure argv[1] exists
  30.     char *array= argv[1];
  31.     foo(array);
  32. }
  33.        
  34. printf ("The string is %s", array);