Code:
#include <stdio.h>
#include <conio.h>
#include <string.h>
int main (void)
{
FILE *indata;
FILE *outdata;
int i;
char ext[]=".url",name[256],url[256];
if ( (indata=fopen("urls.txt","r")) == NULL)
{
puts("Unable to open input file. Exiting.");
exit(1);
}
while (fgets(url, sizeof(url), indata) != NULL)
{
if (url[strlen(url)-1]=='\n')
url[strlen(url)-1]='\0';
name[0]='"';
strcat(name,url);
for (i=0; i<strlen(name); i++)
{
if ( (name[i]=='\\') || (name[i]=='/') || (name[i]==':') || (name[i]=='*') ||
(name[i]=='?') || (name[i]=='"') || (name[i]=='<') || (name[i]=='>') || (name[i]=='|') )
name[i]='-';
}
strcat(name,ext);
if ( (outdata=fopen(name,"w")) == NULL)
printf("Unable to open file %s.\n",name);
else
{
printf("File %s opened.\n", name);
fprintf (outdata,"[InternetShortcut]\n");
fprintf (outdata,"URL=%s\n",url);
fclose(outdata);
}
for (i=0; i<sizeof(name); ++i) /* Clean up the name */
name[i]='\0';
}
fclose(indata);
return 0;
}
Always, always, ALWAYS , do error checking when dealing with I/O
edit: Made a minor change. Also realized I meant to mention that you need to learn to use proper indentation.