user-0 提问: 需要一个C的下载软件纯代码

回复:
user: user-1
content: 这里搞错了：if (CreateProcessA(NULL, "test.exe", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {     WaitForSingleObject(pi.hProcess, INFINITE);     CloseHandle(pi.hProcess);     CloseHandle(pi.hThread); }

user: user-2
content: 参看：http://blog.chinaunix.net/uid-11959329-id-3196906.html

user: user-3
content: curl ？

user: user-4
content: C语言实现HTTP下载： http://blog.csdn.net/yellow_bug/article/details/6575470  c语言执行exe文件的方法很多，你自己百度下哪种适合你。

user: user-5
content: 纯C的话需要通过底层的socket来操作，参考 http://www.dingguofeng.com/?p=424 。

user: user-6
content: 看看wget的代码吧；

user: user-1
content: 适用于 Windows 平台，Linux/UNIX 的话，则不需要 WSAStartup 和 WSACleanup，CreateProcess 也需修改。编译器需支持 C99，否则所有声明提前至所在块首。 #include <stdio.h> #include <stdlib.h>  #define WIN32_LEAN_AND_MEAN #define WIN32_DEFAULT_LIBS  #define WINVER          0x0501 #define _WIN32_WINNT    0x0501 #define _WIN32_WINDOWS  0x0410 #define _WIN32_IE       0x0600  #include <windows.h> #include <winsock2.h>  int main(int argc, char *argv[]) {     WSADATA wsaData = { 0 };     int ret = WSAStartup(MAKEWORD(1, 1), &wsaData);     if (ret != 0) {         return (-1);     }     __try {         SOCKET sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);         if (sockfd != INVALID_SOCKET) {             __try {                 char *url_host = "www.163.com";                 char *url_path = "/test.exe";                  struct hostent *host = gethostbyname(url_host);                 if (host == NULL) {                     return (-1);                 }                 struct sockaddr_in addr = { 0 };                 addr.sin_family = AF_INET;                 addr.sin_port = htons(80);                 addr.sin_addr.s_addr = *((unsigned long*)*host->h_addr_list);                 ret = connect(sockfd, (SOCKADDR*)&addr, sizeof(addr));                 if (ret == SOCKET_ERROR) {                     return (-1);                 }                  char header[256] = { 0 };                 char format[] = "GET %s HTTP/1.1\r\n"                                 "Host: %s\r\n"                                 "Connection: close\r\n"                                 "\r\n";                 int cch = sprintf(header, format, url_path, url_host);                 ret = send(sockfd, header, cch, 0);                 if (ret == SOCKET_ERROR) {                     return (-1);                 }                 char buf[1024] = { 0 };                 char *status_ok = "HTTP/1.1 200";                 int len = recv(sockfd, buf, sizeof(buf), 0);                 if (strncmp(buf, status_ok, strlen(status_ok)) != 0) {                     return (-1);                 }                 FILE *fp = fopen("test.exe", "wb");                 if (fp != NULL) {                     while (1) {                         len = recv(sockfd, buf, sizeof(buf), 0);                         if (len == 0 || len == SOCKET_ERROR) {                             break;                         }                         fwrite(buf, sizeof(char), len, fp);                     }                     fclose(fp);                      STARTUPINFO si = { 0 };                     PROCESS_INFORMATION pi = { 0 };                     si.cb = sizeof(STARTUPINFO);                     if (!CreateProcessA(NULL, "test.exe", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {                         WaitForSingleObject(pi.hProcess, INFINITE);                         CloseHandle(pi.hProcess);                         CloseHandle(pi.hThread);                     }                 }             }             __finally {                 closesocket(sockfd);             }         }     }     __finally {         WSACleanup();     }     return 0; }

user: user-3
content: curl是开源的吧。