fwrite function to write png file stream into a file

This is a discussion on fwrite function to write png file stream into a file within the C Programming forums, part of the General Programming Boards category; Hello, I am writing a code to get the png file from Http server. Once i get the stream, i ...

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    1

    fwrite function to write png file stream into a file

    Hello,

    I am writing a code to get the png file from Http server. Once i get the stream, i want to write the png stream into a file and save it.

    So, i am using fwrite there. It writes some data but I am not able to open the png file.

    Code:

    fwrite(data,1,sizeof(data),fp);

    this is the way to write png file data? Please help.

    Thank you,
    Divya.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Depends on what data is, and therefore what the sizeof(data) is -- unless you are exploiting extra information about what the size of the file is going to be, that is going to be incorrect. Naturally, you do have to also make sure that you've read the whole file, etc.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,532
    My guess would be data is just a pointer, so sizeof() is just plainly the wrong thing to use.

    > I am writing a code to get the png file from Http server.
    So when you do
    len = recv( sock, buff, maxbuffsize, 0 );

    The thing you use in the fwrite call is len.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Write void function output to file!
    By dustydude in forum C Programming
    Replies: 4
    Last Post: 06-15-2010, 09:08 AM
  2. Very slow file writing of 'fwrite' function in C
    By scho in forum C Programming
    Replies: 6
    Last Post: 08-03-2006, 02:16 PM
  3. File stream function problem
    By SpookJP in forum C++ Programming
    Replies: 3
    Last Post: 04-01-2005, 07:55 PM
  4. Passing file stream as function parameter
    By simonc2 in forum C++ Programming
    Replies: 6
    Last Post: 12-22-2004, 11:12 AM
  5. help me to write in a file using a function
    By subbuy2k in forum C++ Programming
    Replies: 1
    Last Post: 12-28-2001, 06:37 AM

Tags for this Thread


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