topical media & game development

talk show tell print

basic-program-solutions-06-Soln6-1.c

? / basic-program-solutions-06-Soln6-1.c


  // Soln6_1.cpp
  include <iostream>
  include <cstring>
  using std::cin;
  using std::cout;
  using std::endl;
  
  int ascVal(int i, const char* p)
  {
     // Output the ASCII value of the character
     if (!p || i > strlen(p))
        return -1;
     else
        return p[i];
  }
  
  int main()
  {
     char* str = "a bunch of bananas";
     int (*fp) (int, const char*);
  
     fp = ascVal;
     for(int n = 0 ; n<strlen(str) ; n++)
     {
       int i = (*fp)(n,str);
  
       cout << "value of '" << str[n] << "' is " << i << endl;
     }
  
     return 0;
  }
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.