Skip to content
Advertisement

I want to write a function that retrieves a webpage

I’m trying to write a function that returns the html code of a specified URL here’s my code so far:

JavaScript

only the first success string is printed: success

JavaScript

here’s my writememorycallback:

JavaScript

the same code when embedded into the body of the main function works just fine.

Advertisement

Answer

If only the first string success is printed out then something probably went wrong with the first call to the curl function.

The first step you should do is to check every return value of curl functions:

JavaScript

The real reason this first call to a curl function failed is that CURL *myHandle wasn’t initialized:

So initialize it:

JavaScript

And delete it after you are done:

JavaScript

The other problem as already pointed out, is that struct BufferStruct buffer isn’t initialized, thus realloc in WriteMemoryCallback fails when called with an uninitialized pointer.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement