Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9175767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:58:14+00:00 2026-06-17T16:58:14+00:00

I am trying to print a dynamically downloaded image returned by cURL as shown

  • 0

I am trying to print a dynamically downloaded image returned by cURL as shown :

    char *raw_image = malloc(1024);

    raw_image = doCurl("GET", img_url, NULL, NULL);

    printf("Content-Type: image/png\n\n");

    fwrite(raw_image, sizeof(raw_image), 20000, stdout);

If I do size smaller than 20000 – image gets cut. How can I make that number dynamic? I don’t want to write to a file – stdout is the best option.

Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:58:15+00:00Added an answer on June 17, 2026 at 4:58 pm

    Ideally you need a way to know the size of the file (image) you are downloading.

    Use libcurl to fetch the header first and get the size.

    Let say you store size in s

    When you alloc the buffer you shoud do

    char *raw_image = malloc(s);
    

    Because s is the size of the data you have to hold not 1024 bytes!

    Download the file and store it in raw_image

    Then

    fwrite(raw_image, 1, s, stdout);
    

    Note that sizeof(raw_image) is the size of the pointer to your buffer, so 8 bytes in a 64bit hw architecture. It’s not the size of the file!

    –

    But….

    –

    You’re fetching an image, and streming it on stdout.

    Why don’t you do a simple call to curl ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create div elements and print items on to them dynamically.
I was trying to dynamically generate fields as shown in http://jacobian.org/writing/dynamic-form-generation/ . My case
am currently using google feed api to get feed links dynamically. am trying to
I'm trying to print some Japanese to a page dynamically using jQuery, and it
I am trying to dynamically get the first and last element from an array.
I'm trying to dynamically construct URLs in an ASP.NET MVC website that point back
Im trying print Excel file data on a page. To do it i used
Im trying to print the realtime output based on user input for a search.
I'm trying to print a number of '+' characters followed by a number of
I'm trying to print a large string to alivepdf. I'm splitting the string by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.