String functions help

This is a discussion on String functions help within the C++ Programming forums, part of the General Programming Boards category; I keep getting this error when I am compiling my program. I am trying to read in this array and ...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    81

    String functions help

    I keep getting this error when I am compiling my program. I am trying to read in this array and then convert all the characters to upper-case, but it is ging me this:

    Code:
    error C2664: 'toupper' : cannot convert parameter 1 from 'char [30]' to 'int'
            This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    Error executing cl.exe.
    Code:
    #include <iostream.h>
    #include <fstream.h>
    #include <iomanip.h>
    #include <ctype.h>
    #include <stdlib.h>
    #include <string.h>
    
    //Global variables
    ifstream infile;
    ofstream outfile;
    
    typedef char str[30];
    
    //function prototypes
    void tocaps(str []);
    
    int main()
    {
    
    int n[30],m[30];
    str name[30];
    
    
    	infile.open("in599A.dat");
    	while(!infile.eof())
    	{
    		for(int i=0;i<23;i++)
    		{
    		infile >> n[i];
    		infile >> m[i];
    		infile.getline(name[i],30);
    		cout << n[i] << endl << m[i] << endl
    		<< name[i] << endl;
    		}
    		
    		//change to caps
    		tocaps(name);
    		//take off the last characters of middle name
    		//compare to second file
    		//add dashes to social security number and add dashes to phone number
    
    		//sort 
    		//binary search
    
    	}
    	
    	return 0;
    }
    
    void tocaps(str name[])
    {
    	for(int i=0;i<23;i++)
    		{
    			name[i]=toupper(name[i]);
    		}
    		for(i=0;i<23;i++)
    		cout << name[i] << endl;
    }

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    toupper() works on single characters, not entire strings. You'd need a nested loop.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    typedef char str[30];
    ...
    str name[30];
    See the issue now?

    [edit] Curses, foiled again! [/edit]

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Jun 2003
    Posts
    81
    cool, thank you. I had a different example in my notes.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 07:02 AM
  2. Replies: 8
    Last Post: 04-25-2008, 03:45 PM
  3. RicBot
    By John_ in forum C++ Programming
    Replies: 8
    Last Post: 06-13-2006, 07:52 PM
  4. Badly designed n string functions?
    By anonytmouse in forum C Programming
    Replies: 3
    Last Post: 11-01-2003, 06:16 AM
  5. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21