Convert Char to Int Function

This is a discussion on Convert Char to Int Function within the C++ Programming forums, part of the General Programming Boards category; 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 ...

  1. #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.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    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.

  3. #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?

  4. #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.

  5. #5
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    ...

    updated code:
    Attached Files Attached Files

  6. #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!!!

  7. #7
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    fetch ya ape!
    Attached Files Attached Files

  8. #8
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    here

    source code
    Attached Files Attached Files

  9. #9
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    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 ....

  10. #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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 12:45 PM
  2. Game Won't Compile
    By jothesmo in forum C++ Programming
    Replies: 2
    Last Post: 04-01-2006, 04:24 PM
  3. Replies: 2
    Last Post: 03-24-2006, 08:36 PM
  4. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 06:20 AM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM

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