Code:
#include <stdio.h>
#include <string.h>
#include <time.h>
/* Prototype */
int fixgets(char *, int ,FILE *);
void wait(long);
int main(void)
{
FILE *fptr, *outptr;
char infoIn[255] = {0}, infoOut[255] = {0}, fname[255] = {0}, oname[255] = {0};
char link[] = "<a target=\"_blank\" href=\"http://www.imdb.com/find?q=", query[200] = {0};
int i = 0, x = 0, y = 0;
printf("Please enter the location of the file to be processed.\n");
fixgets(fname, 255, stdin);
printf("Please enter the location and name of the new file to be saved.\n");
fixgets(oname, 255, stdin);
if ((fptr = fopen(fname, "r")) == NULL || (outptr = fopen(oname, "w")) == NULL)
{
if (fptr == NULL)
{
printf("\n\nI'm sorry, but the file specified could not be opened for reading.\n");
printf("Please close any program accessing the file and make sure the disk is readable.\n");
}
if (outptr == NULL)
{
printf("\n\nI'm sorry, but the file specified could not be opened for writing.\n");
printf("Please ensure you have write access to the disk and try again.\n");
}
printf("\nPress any key to exit..\n");
getch();
if (fptr != NULL)
fclose(fptr);
if (outptr != NULL)
fclose(outptr);
return 1;
}
else
{
do
{
fixgets(infoIn, 255, fptr);
if (infoIn[0] != 0)
{
if (strstr(infoIn, "<td class=\"title\">") != NULL && strstr(infoIn, "imdb.com") == NULL)
{
x = 0;
y = 0;
strcpy(infoOut, "<td class=\"title\">");
printf("infoOut = %s\n", infoOut);
system("pause");
strcat(infoOut, link);
printf("infoOut = %s\n", infoOut);
for (i = 17; i < strlen(infoIn); i++)
{
while (infoIn[i] != '<')
{
query[y] = infoIn[i];
++y;
}
}
printf("query: %s", query);
system("pause");
}
for (i = 18; i < y; i++)
{
if (infoIn[i] != ',')
query[x] = infoIn[i];
else
y = 1000;
++x;
}
printf("query: %s\n", query);
system("pause");
strcat(infoOut, query);
y = 0;
for (i = 0; i <= strlen(infoOut); i++)
{
if (infoOut[i] == '>')
++y;
if (infoOut[i] == ' ' && y == 2)
infoOut[i] = '+';
}
strcat(infoOut, "\">");
strcat(infoOut, query);
strcat(infoOut, "</a></td>");
fprintf(outptr, "%s\n", infoOut);
}
else
fprintf(outptr, "%s\n", infoIn);
for (i = 0; i < sizeof(infoOut); i++)
{
infoOut[i] = 0;
infoIn[i] = 0;
}
} while (!feof(fptr));
fclose(fptr);
fclose(outptr);
}
return 0;
}
/* This routine fixes fgets incorporation of line feeds and other
* ASCII values less than 32 into an input string. Written by H. Brown.
*/
int fixgets(char input_array[], int length, FILE *file_name)
{
register int position=0;
if (fgets(input_array,length,file_name) != NULL)
{
while(input_array[position] != 0)
{ if (input_array[position] < 32) input_array[position]=0;
else ++position;
}
}
/* The length of the string is returned. */
fflush(stdin);
return position;
}
void wait ( long seconds ) {
clock_t limit, now = clock();
limit = now + seconds * CLOCKS_PER_SEC;
while ( limit > now )
now = clock();
}
the problem is: it doesn't output anything but: "></a></td>