C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 02-18-2003, 11:49 PM   #1
Student
 
drdroid's Avatar
 
Join Date: Feb 2002
Location: Montreal, Quebec
Posts: 669
Convert Char to Int Function

Here's the function I use:

Code:
char convert(int* time,char* outtime)
{
	*outtime=(char)*time;
}
here are the errors:

Code:
e:\programs\projects\opengl tests\graphic opengl stardate\sdopengl\stdate.cpp(11) : error C2664: 'convert' : cannot convert parameter 1 from 'char [100]' to 'int *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
e:\programs\projects\opengl tests\graphic opengl stardate\sdopengl\stdate.cpp(18) : error C2664: 'convert' : cannot convert parameter 1 from 'char [100]' to 'int *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
e:\programs\projects\opengl tests\graphic opengl stardate\sdopengl\stdate.cpp(117) : error C2664: 'convert' : cannot convert parameter 1 from 'int' to 'int *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
mainsource.cpp
why? i've looked it through, theoretically it should work.
drdroid is offline   Reply With Quote
Old 02-19-2003, 03:49 AM   #2
Confused
 
Magos's Avatar
 
Join Date: Sep 2001
Location: Sweden
Posts: 3,122
First, your function does not return any value though it says it *should* return a char.

Second, the error doesn't lie in your function. If you look at the errors, it says "cannot convert parameter 1 from char[100] to int*".
Obviously, you're trying to pass a character array to the integer pointer. Have you mixed up the arguments?
__________________
MagosX.com

Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Magos is offline   Reply With Quote
Old 02-19-2003, 10:04 AM   #3
Student
 
drdroid's Avatar
 
Join Date: Feb 2002
Location: Montreal, Quebec
Posts: 669
....

I'm not passing an array. But, I start by creating a char array which get's passed through the function. I then convert the variable into a number that way I can compare it with other numbers. Then I change it back that way I can put it together with the other characters. So would it work if I got rid of the original char array and just made it a char?
drdroid is offline   Reply With Quote
Old 02-19-2003, 10:10 AM   #4
Student
 
drdroid's Avatar
 
Join Date: Feb 2002
Location: Montreal, Quebec
Posts: 669
...

actually no... that's not it... i'll try some other things.
drdroid is offline   Reply With Quote
Old 02-19-2003, 10:21 AM   #5
Student
 
drdroid's Avatar
 
Join Date: Feb 2002
Location: Montreal, Quebec
Posts: 669
...

updated code:
Attached Files
File Type: zip stopengl.zip (6.8 KB, 16 views)
drdroid is offline   Reply With Quote
Old 02-19-2003, 11:09 AM   #6
Student
 
drdroid's Avatar
 
Join Date: Feb 2002
Location: Montreal, Quebec
Posts: 669
scores:

downloads: 2
answers: 0

The downloads are in the lead... but the answers can still catch up!!!
drdroid is offline   Reply With Quote
Old 02-19-2003, 11:46 AM   #7
Registered User
 
Join Date: Sep 2002
Posts: 1,640
fetch ya ape!
Attached Files
File Type: zip stopengl.zip (6.9 KB, 15 views)
Travis Dane is offline   Reply With Quote
Old 02-19-2003, 12:34 PM   #8
Student
 
drdroid's Avatar
 
Join Date: Feb 2002
Location: Montreal, Quebec
Posts: 669
here

source code
Attached Files
File Type: zip stopengl2.zip (6.9 KB, 12 views)
drdroid is offline   Reply With Quote
Old 02-19-2003, 12:43 PM   #9
Crazy Fool
 
Perspective's Avatar
 
Join Date: Jan 2003
Location: Canada
Posts: 2,588
you dont need to convert the char to an int to do comparisons.

example: the following is legit (at least it is with g++)

Code:
char blah = 'A';

if(blah > 40)
    // do stuff ....
Perspective is offline   Reply With Quote
Old 02-19-2003, 12:53 PM   #10
Student
 
drdroid's Avatar
 
Join Date: Feb 2002
Location: Montreal, Quebec
Posts: 669
...

sorry, i should have said this earlier... td solved the problem on irc.
drdroid is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Undefined Reference Compiling Error AlakaAlaki C++ Programming 1 06-27-2008 11:45 AM
Game Won't Compile jothesmo C++ Programming 2 04-01-2006 04:24 PM
Incorporating en-passant and Castling into a chess program mac025 C Programming 2 03-24-2006 08:36 PM
getting a headache sreetvert83 C++ Programming 41 09-30-2005 05:20 AM
Binary Search Trees Part III Prelude A Brief History of Cprogramming.com 16 10-02-2004 03:00 PM


All times are GMT -6. The time now is 04:42 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22