By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,655 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,655 IT Pros & Developers. It's quick & easy.

C++, using Curl, code to copy source of webpage causes errors

P: 29
Here is my code: What it has to do is convert the webpage source into a .txt file, but unfortunately it is causing exceptions. In case anyone asks, I am using Visual C++ 2010 Express.

Why is it not working?

The code:
Expand|Select|Wrap|Line Numbers
  1. #include "curl.h"
  2. #include "easy.h"
  3.  
  4. size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
  5. size_t written;
  6. written = fwrite(ptr, size, nmemb, stream);
  7. return written;
  8. }
  9.  
  10. CURL *curl;
  11. FILE *fp;
  12. CURLcode res;
  13. long lSize;
  14. char *translated;
  15.  
  16. void Func() {
  17.  
  18.     curl = curl_easy_init();
  19.  
  20.     if(curl) {
  21.         fp = fopen("C:\\trans.txt","wb");
  22.         curl_easy_setopt(curl, CURLOPT_URL, "http://paaaagggeeee.com/123.html");
  23.         curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); 
  24.         curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
  25.         res = curl_easy_perform(curl);
  26.         curl_easy_cleanup(curl);
  27.         fclose(fp);
  28.     }
  29.  
  30.     fp = fopen("C:\\Output.txt","rb");
  31.     fseek (fp , 0 , SEEK_END);
  32.     lSize = ftell (fp);
  33.     rewind (fp);
  34.     fread (translated,1,lSize,fp);
  35.     translated[lSize] = 0;
  36.     fclose(fp);
  37. }
  38.  
and here is the error:

1>------ Build started: Project: project1, Configuration: Debug Win32 ------
1> main.cpp
1>c:\documents and settings\alex\my documents\visual studio 2010\projects\project1\project1\main.cpp(19): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 10.0\vc\include\stdio.h(234) : see declaration of 'fopen'
1>c:\documents and settings\alex\my documents\visual studio 2010\projects\project1\project1\main.cpp(27): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 10.0\vc\include\stdio.h(234) : see declaration of 'fopen'
1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuil d.targets(990,5): warning MSB8012: TargetPath(C:\Documents and Settings\alex\my documents\visual studio 2010\Projects\project1\project1\project1.exe) does not match the Linker's OutputFile property value (C:\Documents and Settings\alex\my documents\visual studio 2010\Projects\project1\Debug\project1.exe). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Link.OutputFile).
1>main.obj : error LNK2019: unresolved external symbol __imp__curl_easy_cleanup referenced in function "void __cdecl Func(void)" (?Func@@YAXXZ)
1>main.obj : error LNK2019: unresolved external symbol __imp__curl_easy_perform referenced in function "void __cdecl Func(void)" (?Func@@YAXXZ)
1>main.obj : error LNK2019: unresolved external symbol __imp__curl_easy_setopt referenced in function "void __cdecl Func(void)" (?Func@@YAXXZ)
1>main.obj : error LNK2019: unresolved external symbol __imp__curl_easy_init referenced in function "void __cdecl Func(void)" (?Func@@YAXXZ)
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\Documents and Settings\alex\my documents\visual studio 2010\Projects\project1\Debug\project1.exe : fatal error LNK1120: 5 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Oct 20 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.