Alphabetical order using ASCII values

using ASCII to alphabetize a list of names

Page 1 of 1

1 Replies - 7248 Views - Last Post: 29 February 2008 - 01:11 AM Rate Topic: -----

#1 deaner2425  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-February 08

Alphabetical order using ASCII values

Post icon  Posted 28 February 2008 - 08:55 PM

i am working with data files in C++ and my problem is i have to read in a list a names form two different data files then output them into a third data file in alphabetical order. I have to alphabetize them by assigning them ascII values.

I am having trouble assigning ascii to the first letter of the string variable. im not sure how to do this. i declared my variables then tried to assign the ascii values but its not working

heres what i have
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
//declare variables
string name_1, name_2;
int i ;
char a ;

//declare input data files
ifstream data_1;
ifstream data_2;
//declare output data files
ifstream output;

//open data files
data_1.open("P:\\C++\\data_1.dat");
data_2.open("P:\\C++\\data_2.dat");

//if fails
if(data_1.fail() || output.fail())
{
cout<<"Error with File"<<endl;
return 0;
}




data_1>>name_1;
//data_2>>name_2;
while(!data_1.eof() && !data_2.eof())
{
cout<<name_1<<endl;
//cout<<name_2<<endl;
//='name_1'
char name_1;

cout<<name_1<<endl;

data_1>>name_1;
//data_2>>name_2;

Is This A Good Question/Topic? 0
  • +

Replies To: Alphabetical order using ASCII values

#2 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5365
  • View blog
  • Posts: 27,328
  • Joined: 10-May 07

Re: Alphabetical order using ASCII values

Posted 29 February 2008 - 01:11 AM

Welcome to Dream In Code
:code:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1