Thread: How to include in c program ?

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    9

    How to include in c program ?

    How to include a picture (any format) to c program ?

    How to include a song (any format) to c program ?

    Pls Explain me vth example if possible

    thanx in adv

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Ehm what do you actually want to do? Embed a piece of art in your code, or provide said piece of art by using an external file?

    In most cases, what you would like to do is to use an external file (jpeg, bmp, wav or midi for example) and display or play it. If that's what you want to do, then first of all, you probably need to have SOME programming experience, and your question seems to indicate that you haven't got much of that - maybe some simpler tasks to practice on would help.

    Playing sound is actually not that hard, it only requires a few lines of code. Displaying an image is a tad harder.

    If you want to embed the image/sound in your file, then you will have to find a way to convert your image into a byte-array and then form the relevant data structures from that byte-array, rather than reading from the file.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    9

    Thumbs up

    Yes , i played sound using sound() and no sound() v th different freq.


    i think it is using buzzer on mother board.

    but i want to play mp3 file .


    coming to the image i used different characters to create an image( it took lot of time ) .

    but i want to embedded my photo into a c program
    now am searching for software which converts any format to bits
    as u said, But bitmap image is similar to wht v are seraching for... (i think)

    am using windows Xp ; turbo c compiler

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    WHY is it that everyone is using Turbo C 15 years after it came out? Yes, it _WAS_ a good product at it's time, just like Ford Model T's where good cars at the time they were actively produced.

    I don't think there's a MP3 player built into the Windows API, so you either need to convert it to a wave-form, or find some library that provides the functionality, and there's CERTAINLY none in DOS [To do that in DOS, you'd need to ALSO send a waveform to the soundcard].

    Displaying pictures in DOS involves graphics programming. I don't know for sure if the Borland Graphics library supports 32-bit graphics. Again, it's much easier if you can use Windows rather than DOS. Then it becomes abotu 10 lines of program to display a picture.

    Adding the sound/picture to the program itself will of course add anything up to millions of lines, depending on format and the size of the actual datafile you are adding. This is another point where Turbo C won't hack it - it's got 64KB limits that you'll have to work hard to overcome, when it comes to modern files.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Nov 2007
    Posts
    9

    Smile

    okay, thanx

    Thanx a lot.

  6. #6
    lfs addicted
    Join Date
    Nov 2007
    Posts
    49
    you can do also this way (even if probably is not really beautiful)

    create a program that reads a file as binary (can be an image an mp3) and byte per byte translate it to text in hex form in an array. Someting like:
    Code:
    char data[]="\x67\x03\xff ......."
    and then save this in an header file for example...

    but I do not know which are the limits of this practice...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  2. c program client server
    By steve1_rm in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-24-2008, 10:33 AM
  3. debug assertion failed!
    By chintugavali in forum C Programming
    Replies: 4
    Last Post: 12-11-2007, 06:23 AM
  4. 2d game
    By JordanCason in forum Game Programming
    Replies: 5
    Last Post: 12-08-2007, 10:08 PM
  5. include and program size
    By PierreB in forum C Programming
    Replies: 3
    Last Post: 04-01-2004, 03:34 AM