Hi,
I've written a small code to split a weblink string.
I use it to download a file from web using winsock library.
There's a better way to do this ?
//
#include <windows.h>
#include <stdio.h>
//
int main(int argc, char* argv[])
{
//
LPCSTR szWebLink = "www.google.it/images/firefox/google.gif";
// GET SITE AND FOLDER PATH
LPSTR p = strchr(szWebLink, '/');
INT iSiteLength = (p-szWebLink)+1;
INT iFilePathLength = lstrlen(p)+1;
CHAR szSite[iSiteLength];
CHAR szFilePath[iFilePathLength];
ZeroMemory(&szSite, iSiteLength);
ZeroMemory(&szFilePath, iFilePathLength);
lstrcpyn(szSite, szWebLink, iSiteLength);
lstrcpy(szFilePath, p);
// GET FILE NAME
p = strrchr(szWebLink, '/');
INT iFileNameLength = lstrlen(p)+1;
CHAR szFileName[iFileNameLength];
ZeroMemory(&szFileName, iFileNameLength);
lstrcpy(szFileName, p);
//
printf("full weblink: %s\n", szWebLink);
printf("site: %s\n", szSite);
printf("filepath: %s\n", szFilePath);
printf("filename: %s\n", szFileName);
//
return 0;
}
Thanks!