![]() |
|
#1
|
|||
|
|||
converting text files to html filesWhat are source and destination files. I need an idea on writing a code in c programming in which I have to convert text files to html files. Basically I have to read through each line for specific text tags, that needs to be changed to html tags. Please help :-x
|
|||
|
#2
|
|||
|
|||
|
Quote:
The source file is the input to your program (the text file, I guess). The destination file is the output from your program. The program: Code:
Regards, Dave |
|
#3
|
|||
|
|||
convert text to htmlThanks Dave, but how do you setup two files as a source and destination file. Also how do you take text from one file and write it to another file.
Thanks Ken |
|
#4
|
|||
|
|||
|
You first have to declare a FILE* variable as a handle to the file you want to open, then you must assign the handle to a file and open it via the fopen() command (there are others, but fopen() is probably the most common in console programming). You also must specify how you want to open it, if you want to read from it, write to it, append to it, etc. After opening you then need to check for errors, and if it opened correctly. Once opened, you typically read in a file with the fread(), or write via the fwrite() functions. There are others, but these are the fastest and most efficient. You then need to remember to close the file with fclose(). A simple file reader would look something like this:
CPP / C++ / C Code:
Anyways, hope it helped. |
|
#5
|
|||
|
|||
|
This is the last question I have about this certain task. How do I actually go about processing each line of the input file for changes I need to make to this file.
Thanks Ken |
|
#6
|
|||
|
|||
|
You can scan the buffer you read in for the escape characters/flags you need to change. Some like:
CPP / C++ / C Code:
It's not the most efficient code in the world, but it should work. |
|
#7
|
|||
|
|||
|
Or you can simply add following line in your code to read the file line by line.
CPP / C++ / C Code:
|
|
#8
|
|||
|
|||
|
You can use the fgets() method, but I wouldn't do the sprintf() stuff which you implemented. What you're basically doing is double spacing every line, where all you want to do is to put in a line break tag whenever you come accross a newline escape character.
|
|
#9
|
|||
|
|||
|
You are right Dr. Evil,
I was just trying to give a general example as to how one can read from the file and modify the content (with HTML Tags) and write the new formatted line into a new file. If he just needs to add a new line he can also do CPP / C++ / C Code:
Does this look fine? I am sorry, but I am a bit rusty with HTML scripting. Moreover, his initial post did not mention what kind of formating he needs to do with HTML. He can do whole lots of processing in that while loop , on captured buffer before writing it into the new html file. This is just a sample. |
|
#10
|
|||
|
|||
I forgot to mentionOne thing I forgot to mention is that, fgets will also copy the newline character '\n' from the file into the buffer. So you need to rip it off before you process the line.
CPP / C++ / C Code:
HTH. |
Recent GIDBlog
Toyota - 2009 May Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| phpmyadmin--what format for text files to upload? | bufhal | MySQL / PHP Forum | 0 | 04-Jul-2004 11:07 |
| CD burner wont burn!! | robertli55 | Computer Hardware Forum | 1 | 18-Jun-2004 11:53 |
| Yet another CD burner problem: Lite-On LSC-24082K | Erwin | Computer Hardware Forum | 1 | 22-May-2004 12:28 |
| Can't view pages from another machine on the Intranet | aevans | Apache Web Server Forum | 9 | 14-May-2004 03:26 |
| Manipulating text Files | k209310 | C++ Forum | 0 | 17-Nov-2003 11:23 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The