Thread: toupper function

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    78

    toupper function

    hello all I having a bit of trouble with this little bit of code. observe
    Code:
    #include <iostream.h>
    int main()
    {
    	const int NUMCHARS = 80;
    	char strng[80];
    	int i = 0;
    	char ToUpper(char ch);
    	cout<<"Enter a line of text\n";
    	cin.getline(strng,NUMCHARS);
    
    		while (strng[i] != '\0') 
    		{
    			strng[i] = ToUpper(strng[i]);
    			i++;
    		}
    
    		cout<<"the string with uppercase letters";
    		cout<<  strng <<endl;
    		return 0;
    }
    
    ToUpper(char ch)
    {
    	
    	if (ch >= 'a' && ch <= 'z')
    		return (ch - 'a' + 'A');
    	else
    		return(ch);
    }
    I keep getting error messages saying unresolved external. I've been reading oup on how to convert lower to uppercase letters and if there is an easier way any input would be appreciated thanks and God bless

  2. #2
    Registered User manofsteel972's Avatar
    Join Date
    Mar 2004
    Posts
    317

    Just need to give your function a return type

    Since your function returns a Char you need to declare it as a char.

    char ToUpper(char ch)

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    78

    woops

    details details details, One can never be to careful about them you know

  4. #4
    Registered User
    Join Date
    Feb 2004
    Posts
    127

    Re: toupper function

    Code:
    	
    	if (ch >= 'a' && ch <= 'z')
    		return (ch - 'a' + 'A');
    	else
    		return(ch);
    }
    excuse me .. but can you tell me what is this function for?

    is it for detection of upper case?

    and what do u mean by
    Code:
    return(ch-'a'+'A');
    thanks in advance

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    78

    my retort

    Well the code is designed to change lower case to uppercase. here is the final copy and it is working thanks to all of my dear friends here who helped me find my simple mistake here is the working code
    Code:
    #include <iostream.h>
    int main()
    {
    	const int NUMCHARS = 80;
    	char strng[80];
    	int i = 0;
    	char ToUpper(char ch);
    	cout<<"Enter a line of text\n";
    	cin.getline(strng,NUMCHARS);
    
    		while (strng[i] != '\0') 
    		{
    			strng[i] = ToUpper(strng[i]);
    			i++;
    		}
    
    		cout<<"the string with uppercase letters\n";
    		cout<<  strng <<endl;
    		return 0;
    }
    
    char ToUpper(char ch)
    {
    	
    	if (ch >= 'a' && ch <= 'z')
    		return (ch - 'a' + 'A');
    	else
    		return(ch);
    }
    thank you kindly manofsteel972 for noticing the oversight
    Last edited by drdodirty2002; 03-02-2004 at 05:09 PM.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > if there is an easier way
    Yeah, use the toupper() in ctype.h

    > return (ch - 'a' + 'A');
    This only works on character sets which are contiguous through the alphabet - for example ASCII.
    The EBCDIC character set for example is not contiguous.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM