Thread: copying a mp3 file

  1. #31
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    Quote Originally Posted by CommonTater View Post
    It's fine to continue far as I'm concerned... but maybe we should get back to the OP and his problem...
    Sure. Look, your post count will reach 5k soon. I am looking forward to seeing this :O

  2. #32
    Registered User shubham's Avatar
    Join Date
    May 2011
    Posts
    14
    why is it not working with ch?
    this question is for salem for his first post.
    Last edited by shubham; 05-30-2011 at 02:29 PM.

  3. #33
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by shubham View Post
    why is it not working with ch?
    this question is for salem for his first post.
    It probably works just fine as you're doing it... but copying files character by character is painfully slow.

    My suggestion was to do it in large chunks with fread() and fwrite()... even whole files at once in some cases.

  4. #34
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    EOF is guaranteed to be a negative number outside the range of char. So you squish it back and forth trying to fit it into a byte and then promote it to compare it with something bigger than a byte.

    Let's pretend that instead of bytes, the only thing you can read are single bits. EOF is defined in our example as 10 in binary, and all you can read is 0 or 1.
    Code:
    do
        bit = readbit( file ); /* read 1 or 0 */
    while( bit != 10 ); /* promote a single bit into two bits to compare */
    Ok, so our file is: 001100 in bits. Then it is EOF. What happens in this comparison:

    0 is read, 0 is promoted to 00 and compared with 10
    0 is read, 0 is promoted to 00 and compared with 10
    1 is read, 1 is promoted to 01 and compared with 10
    1 is read, 1 is promoted to 01 and compared with 10
    0 is read, 0 is promoted to 00 and compared with 10
    0 is read, 0 is promoted to 00 and compared with 10
    10 is read, squished into 0, promoted back to 00 and compared with 10

    You have just read the EOF marker, but your program doesn't know you are at EOF, so you merrily read off past the end of your file until your program crashes or something else odd happens. In any event, you have no idea when you've reached the end of your file.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #35
    Registered User shubham's Avatar
    Join Date
    May 2011
    Posts
    14
    what is the value of EOF?

  6. #36
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by shubham View Post
    what is the value of EOF?
    I just told you:
    Quote Originally Posted by quzah View Post
    EOF is guaranteed to be a negative number outside the range of char.
    There is no one specific value, it can be anything negative that is outside the range of a char.


    Quzah.
    Hope is the first step on the road to disappointment.

  7. #37
    Registered User shubham's Avatar
    Join Date
    May 2011
    Posts
    14
    i think it's value is -1 ? but i am not sure. that's why i seek your help quzah

  8. #38
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by shubham View Post
    i think it's value is -1 ? but i am not sure. that's why i seek your help quzah
    Listen to what Quzah is telling us... it could be *any value* that is not a valid ascii or ansi character...
    If you test for -1 and it gets recompiled on a system where it's -128... what happens?

    That is one of the reason we use constants like EOF or MAX_INT in C... because those values can and do change from one compiler to the next.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File Copying
    By jerez_z in forum C Programming
    Replies: 0
    Last Post: 06-02-2004, 05:44 PM
  2. Copying a file
    By shivam in forum Windows Programming
    Replies: 2
    Last Post: 12-22-2003, 02:15 PM
  3. Copying a File
    By thatdude in forum C++ Programming
    Replies: 5
    Last Post: 11-28-2003, 07:07 AM
  4. copying a file
    By Unregistered in forum C Programming
    Replies: 9
    Last Post: 01-10-2002, 09:43 AM
  5. Copying a file
    By rkjd2 in forum C++ Programming
    Replies: 5
    Last Post: 09-09-2001, 10:24 AM