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 3346874
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:21:19+00:00 2026-05-18T01:21:19+00:00

I’m having a bit of a problem with the following code. I’ve seen tons

  • 0

I’m having a bit of a problem with the following code. I’ve seen tons of examples for using InternetReadFile to save to a file. But I cant find one, or get it to work for a char[]. I want to add the szBuffer up to get holdBuff, and then set content equal to holdBuff.

#include <stdio.h>
#include <tchar.h>
#include <string.h>
#include <windows.h>
#include <WinInet.h>

HINTERNET hSession;
void urlToChar(char* url, char** content);

int main()
{
    hSession = InternetOpen("Mozilla/4.0 (compatible) Poison", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
    char* content;
    urlToChar("http://google.com/", &content);
    printf("%s",content);
    return 0;
}

void urlToChar(char* url, char** content)
{
    HINTERNET hConnect = InternetConnect(hSession, _T(""),INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
    HINTERNET hRequest = InternetOpenUrl(hSession, url, NULL, 0, 0, 0);
    if (hRequest)
    {
        char holdBuff[] = "";
        char szBuff[1025];
        memset(szBuff, 0x00, sizeof(szBuff));
        DWORD bytesRead;
        while (InternetReadFile(hRequest, szBuff, 1024, &bytesRead) == TRUE && bytesRead > 0)
        {
            // Cat szBuff to holdBuff
            memset(szBuff, 0x00, sizeof(szBuff));
        }
        *content = holdBuff;
        // memset(holdBuff, 0x00, sizeof(holdBuff));  <-- Need this?
    }
    InternetCloseHandle(hRequest);
    InternetCloseHandle(hConnect);
}
  • 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-05-18T01:21:19+00:00Added an answer on May 18, 2026 at 1:21 am

    The variable declaration

    char xyz[] = "Hello World!";
    

    will tell the compiler to put the contents of the string on the stack. Of course, the stack goes away when your function returns.

    So in your case:

    char holdBuff[] = "";
    ...
    *content = holdBuff;
    

    This tells the compiler to create a string of length one (the NULL terminator) as a local variable. Just because you’ve set the value of content to holdBuff doesn’t mean that what holdBuff was pointing exists anymore.

    You have to correct two things. Firstly, you must use strcpy() or similar function. Second, you must allocate sufficient space for holdBuff.

    Example:

    char holdBuff[4096];    // or some other sufficiently large size
    ...
    *content = malloc (strlen(holdBuff) + 1);
    strcpy (*content, holdBuff);
    

    You’ll then need to free(content) in main() once you’re finished with it.


    Now, for how to actually do the concatenation: Your performance will be much better if you forget about using szBuff at all and just write directly to holdBuff.

    char* temp = holdBuff;
    while (InternetReadFile(hRequest, temp, 1024, &bytesRead) == TRUE && bytesRead > 0)
    {
        temp += bytesRead;
    }
    *temp = '\0';    // manually append NULL terminator
    

    Now holdBuff will have the data you want with no need for intermediary concatenation.

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

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.