Thread: How do I cast a char Array[] to a const char* ?

  1. #1
    Unregistered
    Guest

    Question How do I cast a char Array[] to a const char* ?

    Hi,
    I m working on a console MP3 player using the FMOD Sound Library. In this library, the function to open an MP3 file has this signature:
    FSOUND_Stream_OpenFile(const char *filename);
    In my MP3 player, I would like the user to be able to input the filepath and name of the song he/she wants to play, and the Player to open the respective song.

    I thought the code could look like this:

    //...
    char PathInput[30];
    cout << "Please enter the name of the song (incl. path) you want to open." << endl;
    cin.getline(PathInput, 30);
    FSOUND_Stream_OpenFile(PathInput);
    //...

    However, this code does not work, since the function needs a const char*, and not a char*. Is there anyway of casting the char* to a const char*, i.e. making the compiler think that what it is passing in to FSOUND_Stream_OpenFile is a const char*?

    If this isn't possible, is there a way of converting the char* to a const char*?

    Any help or suggestion is greatly appreciated!!!

    MCMalayalam

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    FSOUND_Stream_OpenFile(const PathInput);
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User larry's Avatar
    Join Date
    Sep 2001
    Posts
    96
    Include <string> library. Create a string type variable. Use this variable with getline function. Pass return value of your_variable_name.c_str() function to FSOUND_Stream_OpenFile(PathInput) function as a PathInput parameter. Advantage: you don't have to worry about size limit (e.g. 30). If you need code, I'll try to write it.
    Please excuse my poor english...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  2. Conversion Char To Char * Problem
    By ltanusaputra in forum Windows Programming
    Replies: 3
    Last Post: 03-01-2008, 02:06 PM
  3. Including The Right DLLs
    By bumfluff in forum Game Programming
    Replies: 8
    Last Post: 12-28-2006, 03:32 AM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  5. comparing fields in a text file
    By darfader in forum C Programming
    Replies: 9
    Last Post: 08-22-2003, 08:21 AM