lundi 6 avril 2015

Reading specific characters into a char array

I am struggling with this one question. I have a file called chars.dat which contains the following data: a b C z 113 word s t. I have to read only characters in the range of A...Z and/or a...z, and integers have to be converted to their character value and only be added to the array if it fits in the given range, and string have to be ignored. I have been trying quite a bit, but no luck. This is my code, and I am completely stuck, all help will be greatly appreciated:



using namespace std;

/* the array that will store the elements read from file, size of the array,
and name of file to be read.
*/

string fileName;
char c;
cout << "Please enter the file name to be read: ";
getline(cin, fileName);

file.open(fileName);

if (file)
{
while (file >> c && c > 'A' && c < 'Z' || c < 'a' && c > 'z'){

cout << c;

}
}
}

Aucun commentaire:

Enregistrer un commentaire