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;

   getString(string);

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

   count = numGraph(string);

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

   reverseCase(string);

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

   system("PAUSE");
   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

      string.

   \***************************************************************/

   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);

}

You must initialise 'count' in numGraph().

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.