Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

C-style or function-style cast within a class method

Posted on 2003-03-04
8
Medium Priority
?
263 Views
Last Modified: 2006-11-17
This is my problem;
error C2664: 'isspace' : cannot convert parameter 1 from 'char *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.          

This is the section of code;
if(isspace(pSSNumber[i])){ // Determines it is a tab or space

Note: pSSNumber is char* class_name::pSSNumber.

This is the solution, maybe?;
if(isspace(int(pSSNumber[i]))){ // Determines it is a tab or space }

Note: the int() cast.

My question is; is there a better solution.  It turns out that I have to do a cast on many statements.  Seems to me that there should be a global solution.
0
Comment
Question by:chima
8 Comments
 

Expert Comment

by:Jasonss
ID: 8068095
how about writing your own isspace() function that take char*
0
 
LVL 8

Accepted Solution

by:
Exceter earned 200 total points
ID: 8068118
char and int are synonymous terms. You will have no difficulty passing a char to isspace(). However, char* is a pointer to a char array, not a char. Your error leads me to beleive that pSSNumber is a multidimensional array. If so, this is your problem because a multi dimensional array is simply an array of pointers. Assuming that it is a two dimensional array you would check the first character in the array by saying,

if( isspace( pSSNumber[i][0] ) )

Could you post the section of code in which pSSNumber is declared?

Exceter
0
 
LVL 6

Expert Comment

by:thienpnguyen
ID: 8068123
Are you sure, pSSNumber's type is char* .

I almost think, in your program pSSNumber's type is char** .

Could you check it .
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 8

Expert Comment

by:Exceter
ID: 8068141
>> how about writing your own isspace() function that take char*

Because char* is a pointer not a char. char* variables are not used to store characters so writing a function that checked to see if its value was equivalent to a space character would be pointless.

Exceter
0
 

Author Comment

by:chima
ID: 8068244
I believe that Exceter is right.  pSSNumber is a two demensional array. I had move this section of code from main(){} and did not think of the input statment for the array.  I will try Exceter's solution, then issue the points.  I'm new at this, therefore writing my own isspace would require more skill than what I have.

Sidebar: I did not get an email telling me that there were responses.  I wonder why?  Also, I saw that the status was/is <unlocked> what does this mean?  I read the links for "New EEs" but have not come accross its meaning.
I hope and I think that the question is still open.
0
 
LVL 8

Expert Comment

by:Exceter
ID: 8068322
>> I did not get an email telling me that there were responses.  I wonder why?  

The email notifications get behind once in a while, the notification will show up.

>> Also, I saw that the status was/is <unlocked> what does this mean?

That simply means that you have not accepted an answer to this question yet.

Exceter
0
 

Author Comment

by:chima
ID: 8068481
Exeter, you're smart and quick, thanks.
It worked.  Silly me for thinking that the problem was more difficult.  I have another question, which I will post tomorrow.  Once again thanks.
0
 
LVL 8

Expert Comment

by:Exceter
ID: 8068699
You are most welcome.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question