Mega Code Archive

 
Categories / C++ Tutorial / Array
 

Index a pointer as if it were an array

#include <iostream>  #include <cctype>  using namespace std;    int main()  {    char *p;    int i;    char str[80] = "This Is A Test";      cout << "Original string: " << str << "\n";      p = str;     for(i = 0; p[i]; i++) {      if(isupper(p[i]))        p[i] = tolower(p[i]);      else if(islower(p[i]))        p[i] = toupper(p[i]);    }      cout << "Inverted-case string: " << str;      return 0;  } Original string: This Is A Test Inverted-case string: tHIS iS a tEST