I am working on a C++ program that wants me to read in 52 unsorted states. All the states have randomly Capitalized letters.The objective is to sort the states in alphabetical order by the last letter of the state. Case sensitivity is the least of my problems but i am haveing trouble comparing the states to one another, i am almost done with the program but am running into some errors.

Here is my Code.

#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;

char StateNames[53][50];
char TempArray[2][50];
char X;
int main()
{


  ifstream inFile;
  ofstream Report("States.out");
     char FileName[50];
     cout<<"What is the name of the file?"<<endl;
     cin>>FileName;
     inFile.open (FileName);

           while(!inFile.eof)       //To read in from the file into the array
             {
               for (int i=0; i<53;i++)
                inFile>>StateNames[i][50]>>ws;
             }

          for(int i=0; i<53; i++)
           for(int j=0;j<50;j++)
             cout<< StateNames[i][j];//To display the names as they originally were

             cout<<"This is how the states were Sorted first^^"<<endl;

              for (int i=0;i<53;i++)             //main sort loop
               for (int j=0;j<1000;j++)
                {  
                X=strlen(StateNames[i][50]);//To find the last charactor in the 
                StateNames[i][X]=toupper(StateNames[i][X]);//string

                  if (StateNames[i][X] > StateNames[j][X]) // Not sure if formula is correct
                   {
                    strcpy (TempArray[1][50],StateNames[i][50]);
                    strcpy (StateNames[i][50],StateNames[j][50]);
                    strcpy (StateNames[j][50],TempArray[i][50]);            /// sort
                   }

                } 
        for(int i=0;i<53;i++)  // To send Data to the output file
         Report<<StateNames[i][50]<<endl;       




}

E:\Project csci 122.cpp In function `int main()':

20 E:\Project csci 122.cpp could not convert inFile.std::basic_ios<_CharT, _Traits>::eof [with _CharT = char, _Traits = std::char_traits<char>] to bool

20 E:\Project csci 122.cpp in argument to unary !

35 E:\Project csci 122.cpp invalid conversion from char to const char*
35 E:\Project csci 122.cpp initializing argument 1 of size_t strlen(const char*)

40 E:\Project csci 122.cpp invalid conversion from char to char*
40 E:\Project csci 122.cpp initializing argument 1 of char* strcpy(char*, const char*)
40 E:\Project csci 122.cpp invalid conversion from char to const char*
40 E:\Project csci 122.cpp initializing argument 2 of char* strcpy(char*, const char*)

And these are the jist of my errors.

Any Insight

My book shows all about comparing numerical arrays but nothing involving strings at all
Please help thanks!

I'm sorry, I can't read your code very well.

Are they full state names or abbreviations? Either way, I doubt you need strings that are 50 chars long. Unless there is one I'm missing, you should only need about 20 chars.

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.