Hi, I'm trying to work on a program to reverse string input upper case to lower case vice versa. I got that part working but the second thing is I have to count the number of graphical character from user input. I'm a bit confused about using pointer as well.
Here is my code

#include <iostream>
#include <ctype.h>

using namespace std;

const int STRINGSIZE = 100;

// prototype declaration
void reverseCase(char string[]);
int numGraph(char string[]);
void getString(char string[]);

int main()
   char string[STRINGSIZE];
   int count;


   cout << "Entered string => " << string << "\n";

   count = numGraph(string);

   cout << "Number of graphic characters in string = " << count << "\n";


   cout << "Reverse case   => " << string << "\n";

   return 0;


void reverseCase(char string[])


      Reverse the case of all alphabetic characters in the string.

      That is, all upper case characters become lower case and 

      all lower case become upper case.


   int i;
   for (i = 0; string[i]; i++) 
       if (isupper(string[i]))
            string[i] = tolower(string[i]);
       else if(islower(string[i]))
            string[i] = toupper(string[i]);

int numGraph(char string[])


      Calculate the number of printable graphic characters in the



   int i, count;

   for (i=0; string[i]!= '\0'; i++)
      if (isgraph(string[i])) count++;

   return count; 


void getString(char string[])


      Use getline function to get entire line of text up to

      maximum of STRINGSIZE-1 chars in length


   cout << "Please enter a string to process\n";
   cin.getline(string, STRINGSIZE);

8 Years
Discussion Span
Last Post by MrSpigot
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.