Easy file download for C/

Source: Internet
Author: User
First, let's start with a few APIs.

_getcwd

Gets the current working directory.

Char *_getcwd (      char *buffer,     int maxlen   );

Buffer

Storage location for the path.

MaxLen

Maximum length of the path in Characters:char for _GETCWD and wchar_t for _WGETCWD.

Easy to know: buffer is the path

MaxLen: Is the length

function is to get the path of the current program

Next API

Urldownloadtofile function

Downloads bits from the Internet and saves them to a file.

Char *_getcwd (      char *buffer,     int maxlen   );  wchar_t *_wgetcwd (      wchar_t *buffer,     int maxlen   );

Here's the code:

#include <Windows.h>  #include <stdio.h>  #include  <direct.h>    #pragma comment (lib , "URlmon")    int main ()  {      char buffer[max_path];      _GETCWD (buffer, MAX_PATH);      strcat_s (buffer, "//1.jpg");      HRESULT Result = Urldownloadtofilea (NULL, "HTTP://112.22.245.11:443/DOWN/DE0243D60205717A2A74AEA53C0C500C-46353/1". jpg?cts=yd-f-u13274580&    ctp=111a23a228a125&ctt=1484747960&limit=1&spd=1300000&ctk= 4ab73a4a76e47ad0b181d0f9fc47b6a1&chk=de0243d60205717a2a74aea53c0c500c-46353 ", buffer, 0, NULL);      Switch (Result)      {case      s_ok:printf ("The download started successfully.\n");      Case e_outofmemory:printf ("The buffer length is invalid, or there are insufficient memory to complete the operation.\n"); break;      }      return 0;  }

Program run:

The above is the easy implementation of the content of the file download, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.