Help...using strings and txt files

This is a discussion on Help...using strings and txt files within the C Programming forums, part of the General Programming Boards category; I have 99% of the program done and all I have left is to write the rest of the functions ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    6

    Help...using strings and txt files

    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
    Last edited by Juicehead; 11-26-2002 at 09:03 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Worksafe Array of Strings
    By Hawkin in forum C Programming
    Replies: 4
    Last Post: 03-29-2008, 12:00 AM
  2. Retrieve string(s) from (txt) file
    By Gordon in forum Windows Programming
    Replies: 12
    Last Post: 08-10-2007, 04:34 PM
  3. Replies: 12
    Last Post: 10-17-2005, 07:49 AM
  4. Writing strings to file
    By Ichmael™ in forum C++ Programming
    Replies: 6
    Last Post: 07-12-2005, 01:37 PM
  5. freopen and strings
    By Juicehead in forum C Programming
    Replies: 3
    Last Post: 11-21-2002, 08:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21