C ++

  Smithick 12:44 29 May 2003
Locked

Dear... everyone

I have Microsofts Visual C++ 6.0.
I also have a big error in it.

I use the 'toupper' statements to compare two strings yet if I leave out the header file '#include ctype>'. All the lines with 'toupper'() display error C2664. If I add in the heading line, that line itself becomes the only error!
Am I spelling the heading statement wrong. Though this would cuase a degree of embarassment it would also be easily corrected.

  The Ghost of Inept Pig 12:51 29 May 2003

Shouldn't that be:

#include <ctype.h>

  Smithick 13:14 29 May 2003

I do believe both

'#include<ctype>'
'#include<ctype.h>'

work Ghost. yet for the first line an extra line is needed 'using namespace.std;'. It allows the computer to recognise differnet strings that have the same name(or something).

I actually think I have spelt the <ctype> wrong as it could be cctype. Anyway it is the header file to allow typecasting of any strings in the program.

  davidg_richmond 14:44 29 May 2003

Smithick - What is the line of code involving toupper? I think this is where the problem lies and not the header. Are you converting a string or a single character? It will only work on a single char.

#include <ctype> only works if you have Visual C++ set to take it (its somewhere in the Preferences).

  Smithick 14:55 29 May 2003

The line involving the 'toupper' statement is
'infile.getline(toupper(cdtitle), 40, '/');'

I'm reading data from a file and want the character array 'cdtitle' to be changed to uppercase letters so I can compare them to another character array.

Thanks for any help.

  davidg_richmond 15:14 29 May 2003

The problem lies in using a character array in full with toupper, as it will only take single characters.

You would be better creating a new procedure, such as 'uppercase(char* cdtitle)'

then

int i=0;
while (str[i] != '\0')
{
cdtitle[i]=toupper(cdtitle[i])
i++;
}

when you return the character array should be in upper case. you may need to tweak my coding though, it's been a year since i've used C++ frequently.

  Smithick 11:29 02 Jun 2003

Indeed the context behind the code does work. I have no errors yet still it is not good enough.

Thanks for your help folks.

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

AMD Radeon Adrenalin release date, new features, compatible graphics cards

Indie publisher Canongate’s top 10 book covers of 2017

New iMac Pro release date, UK price & specs rumours

Tablettes Amazon Fire : quel modèle choisir ?