Thread: Uppercase/Lowercase/Word COunt/Char count

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    29

    Uppercase/Lowercase/Word COunt/Char count

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    #define STRINGSIZE 100
    
    /*Prototypes*/
    
    void getString(char *string);
    void lowToUpper(char lowerData[]); //convert the string to uppercase
    void upToLower(char upperData[]); //convert the string to lowercase
    int numGraph(char *string); //counts # characters
    
    /*Main program input*/
    int main(int argc, char *argv[])
    {
      
      char string[STRINGSIZE];
       int count;
    
       getString(string);
       printf("Entered string => %s", string);
    
       count = numGraph(string);
       printf("Number of characters in string = %d\n", count);
      
      
      
      lowToUpper(lowerData)
      upToLower(upperData)
      
      
      
      system("PAUSE");	
      return 0;
    }
    
    
    /*void codes*/
    
    void lowToUpper(char lowerData[])
         {
                         for (i=0; i<strlen(string); i++)
                         if (isupper(string[i]))
                         string[i]=tolower(string[i]);
         }
         
    void up ToLower(char upperData[])
         {
                         for (i=0; i<strlen(string); i++)
                         if (islower(string[i]))
                         string[i]=toupper(string[i]); 
         }
    int numGraph(char *string)
    {
    	int i, count = 0;
    	for (i = 0; string[i] != '\0';i++)
    	{
    		if (isgraph((int)string[i])) count++; 
    	}
    	return count;
    }
    
    void getString(char *string)
    {
       printf("Please enter a string to process\n");
       fgets(string, STRINGSIZE, stdin);
    }
    What I have so far, I need the program to get the string, print out the string in uppercase and then in lowercase and display the number of words and the number of characters

  2. #2
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    So what you need is a word counting function?

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    29
    Quote Originally Posted by Subsonics View Post
    So what you need is a word counting function?
    I actually havent added that yet, I havent gotten these to work yet

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    So what is the problem that has you stumped? The requirements of the assignment are your concern, are they not?

    This part confuses me:

    lowToUpper(lowerData)
    upToLower(upperData)

    Don't you want to pass in string[]? If not, then what?

    "lowerData" and "upperData" are nowhere in main(), so they can't be passed into these weirdly named functions.

    C'mon, if a string doesn't exist in main(), how can you pass it in as a parameter, from main(), to a function called by main()?

    You need to get cracking on these problems.

  5. #5
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Quote Originally Posted by Charak View Post
    I actually havent added that yet, I havent gotten these to work yet
    What I was getting at was if you had an actual question. Or if you just wanted us to debug your code without even telling what the problem is.

  6. #6
    Registered User
    Join Date
    Jan 2011
    Posts
    29
    Code:
    /*void codes*/
    
    void lowToUpper(char lowerData[])
         {
                         int i;
                         for (i=0; i<strlen(string); i++)
                         if (isupper(string[i]))
                         string[i]=tolower(string[i]);
         }
         
    void upToLower(char upperData[])
         {
                        int i;
                         for (i=0; i<strlen(string); i++)
                         if (islower(string[i]))
                         string[i]=toupper(string[i]); 
         }
    int numGraph(char *string)
    {
    	int i, count = 0;
    	for (i = 0; string[i] != '\0';i++)
    	{
    		if (isgraph((int)string[i])) count++; 
    	}
    	return count;
    }
    
    void getString(char *string)
    {
       printf("Please enter a string to process\n");
       fgets(string, STRINGSIZE, stdin);
    }
    editted, says strings are undeclared in the void types

  7. #7
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    "string" is not declared in the same scope as these functions, upperData and so on, is on the other hand. Likewise upperData, etc is not declared in main.

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You need to replace "upperData" and "lowerData" with "string", or you can't work with the string[] array, in those functions.

    If you want to use a copy of string[] in those functions, then you need to declare them (probably inside their functions), and then strcopy(lowerData, string);, to copy the char's over to lowerData (for instance).

    Now you can change lowerData[], to all lowercase letters, and leave string[] char's unchanged.

    And you're ready to do the same thing for upperData[].

    That could work nicely.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 12-07-2010, 06:53 AM
  2. Can you help me about tolower() in file
    By nctar in forum C Programming
    Replies: 7
    Last Post: 05-12-2010, 10:04 AM
  3. bintree and count (withouth using template)?
    By cubimongoloid in forum C++ Programming
    Replies: 7
    Last Post: 05-24-2009, 06:22 AM
  4. input question
    By piyush_v in forum C Programming
    Replies: 9
    Last Post: 04-12-2007, 07:09 AM
  5. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM