You are not logged in.

#1 2008-08-20 13:02:10

fawx
Member
Registered: 2008-08-20
Posts: 8

Using variables in CURL for urls.

Hello, I am fairly new here and new to programming. I am trying to make a program that will ask for a url and store it in a character array and use that variable as the URL for the url argument, in quotations, using libcurl, of course.

curl_easy_setopt(curl, CURLOPT_URL, "<here>");

However, when I do it the way I would with printf()

curl_easy_setopt(curl, CURLOPT_URL, "%c", &...);
it says prg.c:12:53: error: macro "curl_easy_setopt" passed 4 arguments, but takes just 3

Is there a way to do what I am trying to do?

Last edited by fawx (2008-08-20 13:06:24)

Offline

#2 2008-08-20 15:42:21

alienman
Member
From: Mexico
Registered: 2008-07-08
Posts: 106

Re: Using variables in CURL for urls.

I don't know what u really want to do. And what I found is that there is not an overloaded function like the one you are trying to use, in fact there is no overloaded functions for that one.

http://curl.haxx.se/libcurl/c/curl_easy_setopt.html

CURLcode curl_easy_setopt(CURL *handle, CURLoption option, parameter);

If you want to pass a URL that dynamically fills the parameter variable you can first create a string and copy the info from another one then concatenate another.

Here is an example that maybe could help you.

char url[128];
char *page = "hello.html";
strcpy( url, "www.google.com" );
strcat( url, page );

for this you must include string.h, then you can use url to send as parameter in your function.


ISC - Ignacio Marmolejo
ArchLinux & GNOME User.

Offline

#3 2008-08-20 16:10:19

nogoma
Member
From: Cranston, RI
Registered: 2006-03-01
Posts: 217

Re: Using variables in CURL for urls.

If you're trying to build strings from user input, you can do strcpy stuff as shown above, or look at sprintf

man sprintf

It behaves like printf, but instead of writing to STDOUT, it will write it to a string. So, you can build your dynamic string that way, and then pass the result as the 3rd parameter to your curl function.


-nogoma
---
Code Happy, Code Ruby!
http://www.last.fm/user/nogoma/

Offline

#4 2008-08-20 21:56:48

fawx
Member
Registered: 2008-08-20
Posts: 8

Re: Using variables in CURL for urls.

What lib does strcpy use?

Offline

#5 2008-08-21 21:54:51

alienman
Member
From: Mexico
Registered: 2008-07-08
Posts: 106

Re: Using variables in CURL for urls.

string.h


ISC - Ignacio Marmolejo
ArchLinux & GNOME User.

Offline

Board footer

Powered by FluxBB