I have 99% of the program done and all I have left is to write the rest of the functions to replace and process the tags. What I was asked to do was to write a program to use 3 txt files. one to read in, one to contain tags to replace those in the txt file and one to print to
Code:
#include "frmlet.h"
//reads in the whole form
void read_letter(string form_txt,
char get_form[MAX_LINE][MAX_CHAR],
int *form_count)
{
int i;
freopen("form.txt","r",stdin);
scanf("%i", form_count);
for (i=0; i<*form_count; i++)
{
scanf(" %119[6\n]", get_form[i]);
}
return;
}
//reads in the tags and replacement names
void read_tag(string tag_txt,
char get_tag[MAX_LINE][MAX_CHAR],
char replace[MAX_LINE][MAX_CHAR],
int *tag_count)
{
int i;
char end[] = ">";
freopen("tags.txt","r",stdin);
scanf("%i", tag_count);
for (i=0; i<*tag_count; i++)
{
scanf(" %10[^>]> %25[^\n]", get_tag[i], replace[i]);
strcat(get_tag[i], end);
}
return;
}
//replaces the form tags with the names
void string_replace(char get_form[MAX_LINE][MAX_CHAR],
char get_tag[MAX_LINE][MAX_CHAR])
{
char temp[MAX_CHAR] = "";
char *P, *Q, *R;
P= strstr(...,...);
while (P!= NULL)
{
Q = P+strlen(get_tag);
*P = '\n';
temp[0] = '\0';
}
return;
}
//processes the replacements
void process(char get_form[MAX_LINE][MAX_CHAR],
int form_count,
char get_tag[MAX_LINE][MAX_CHAR],
char replace[MAX_LINE][MAX_CHAR],
int tag_count)
{
int i,j;
for (i=0; i<form_count; i++)
for (j=0; j<tag_count; j++)
{
string_replace();
}
return;
}
//prints the new form to a text file
void print_letter(char get_form[MAX_LINE][MAX_CHAR],
int form_count)
{
int i;
for (i=0; i<form_count; i++)
{
puts(get_form[i]);
}
return;
}
I am stuck at the string_replace and process functions
I know I need to use strcat but where?
thx