Need help with improving my programming
I need help with improving and optimizing my program. My original plan was to create a small man2html program but it seems now that is more like a general txt2html.
I am trying to get my code so close to ANSI-C standard as possible.
Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define MAX 10000
#define LITE 100
void str2html();
char words[MAX];
FILE * fp;
FILE * st;
int main()
{
char readFile[LITE];
char writeFile[LITE];
printf("Enter file to open\n");
scanf("%s", &readFile);
printf("Enter file to write to\n");
scanf("%s", &writeFile);
fp = fopen(writeFile, "w");
st = fopen(readFile, "r");
fflush(stdin);
fprintf(fp, "<html>\n<head>\n<body bgcolor=""white"">\n</head>\n");
while (fgets(words, MAX, st) != NULL && words[0] != '\0')
fprintf(fp, "%s <br>", words);
fprintf(fp, "\n</body>\n</html>");
str2html();
fclose(st);
fclose(fp);
return 0;
}
void str2html()
{
int val;
char str[LITE];
char *pdest;
printf("Do you want to make html links? 1 for yes, 2 for no\n");
scanf("%d", &val);
while (val == 1)
{
printf("Enter word to make a link to\n");
scanf("%s", &str);
pdest = strstr(words, str);
if (pdest != NULL)
{
char ch[100];
printf("Enter shortcut to the word\n");
scanf("%s", &ch);
fprintf(fp, "<a href=%s%s.html>", ch, str);
fprintf(fp, "%s", str);
fprintf(fp, "</a> ");
}
else
printf("Error\n");
printf("Do you want to continue? 1 for yes, 2 for no\n");
scanf("%d", &val);
}
printf("Exit\n");
}
Thanks in advance.