GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 10-Jun-2006, 00:58
betazee betazee is offline
New Member
 
Join Date: Jun 2006
Posts: 6
betazee is on a distinguished road

convert C to HTML!


i was messing around and wondering if we can convert C into html. my idea is to replace all the greater-than or less-than character when we pull a certain program that already stored:

replace "<" with "&lt;" and ">" with "&gt;" when we pull up the program
(beacause html don't use "<" or ">" in the code. )

for examplerginal program :

CPP / C++ / C Code:
#include <stdio.h>
#include <stdlib.h>

/* Function Prototypes */
FILE* fileOpen( char[20], const char * );
int copyFile( FILE*, FILE* );

output of program

Code:
#include &ltstdio.h&lt #include &ltstdlib.h&lt /* Function Prototypes */ FILE* fileOpen( char[20], const char * ); int copyFile( FILE*, FILE* );

i'm looking for surgestion. thank u



here is wat i have so far

CPP / C++ / C Code:
#include <stdio.h>
#include <stdlib.h>

/* Function Prototypes */
FILE* fileOpen( char[20], const char * );
int displayFile( FILE* );

int main()
{
    /* our file pointer stores information about file status */
    FILE *FilePtr;
   
    char  displayFilename[20]; 
   
    int reterr;
    
    printf("\nPlease enter the full name of the file you want to display.");
    printf("\nFilename must be less than or equal to 20 characters long:  ");
    scanf("%20s", displayFilename );
    
    FilePtr = fileOpen( displayFilename, "r"  );
    if ( !FilePtr ) {
         printf("\nError! opening file %s.  We will exit the program\n",
                 displayFilename );
         system("pause");
         return 1;
    } 
     
    /* Our file is open and ready to display */
    displayFile( FilePtr );

    /*  close the file   */
    fclose( FilePtr );
 
    system("pause");
    return 0;
}
/**********************************************************
       Function fileOpen
       
       Mostly this was written as a function just for
       illustration purposes - it doesn't seem to reduce our cod
       by much, but its useful to know how to do this.
       
***********************************************************/
FILE* fileOpen( char fname[20] ,const char *mode  ){
    
    FILE *fptr;
    
    /* lets open our file & exit if there is an error */
    fptr = fopen( fname , mode);
    if (! fptr ){
        return NULL;
    }
   
    return fptr;
}

/**********************************************************
       Function displayFile
             
***********************************************************/
int displayFile( FILE* fptr ){
    char line[ 100 ];
    
    /* THIS DEMOS THAT WE CUT OFF AT N-1 - change to 100 to read full file*/
    fgets( line, 30, fptr );
     
    while ( !feof( fptr)) {
       /* write line to std output */
       puts( line );
       /* get next line from our file */
       fgets( line, 30, fptr ); 
    }
    
    printf("\n\nThe file display operation has completed. \n\n");
    
    return 0;
}
Last edited by LuciWiz : 12-Jun-2006 at 05:36. Reason: Please insert your C code between [c] & [/c] tags
  #2  
Old 10-Jun-2006, 10:34
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,712
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: convert C to HTML!


Quote:
Originally Posted by betazee
i was messing around and wondering if we can convert C into html

I like it! It sounds like a fairly straightforward project to increase your knowledge of C and of html.

Quote:
Originally Posted by betazee
i'm looking for surgestion

Suggestion number 1: Make a plan (ya gotta have a plan). See footnotes.

You have the beginnings of a program specification: replace '<' and '>' with stuff that works with html.

You have the beginnings of a program: Takes a C file and replaces '<' and '>' with stuff that you hope works with html.

What you need is a test plan. I never, ever start coding (even pseudo coding) a project without some idea of how I am going to test it.

Here is one approach --- the test plan is to look at your browser's rendering of the html stuff.

SO: put the output of your program into a file. Call the file, say, z.htm or z.html or some such thing.

Then, in your browser, open your html file. (In Microsoft IE select Open from the File menu. In Firefox click "Open file" from the File menu.)

What happens?

If it looks OK, then try bigger files with more "C" stuff (Maybe there are things that need to be changed other than '<' and '>' ? Or, maybe, not. Maybe you can find a good html reference and browse through it for additional information.)

Now if it doesn't look like you thought it should, how can you fix it? Well, you could go through the html reference and try to see how to get your desired output.

Here's what might be a quicker way: Pick a page on some web site (like your original post on this forum, for example) and view its source.

On either browser, open the page (the normal html view, as I suggested above) and then right-click within the page's window. Click on "view source" and the file's html source will open with a text editor. Look at places where '<' and '>' were displayed OK in the html view. How does the gt and lt stuff actually work? How does it get a newline so that each source code line is on its own line in the html view?

I suggest that you first make changes directly in your html file so that it looks OK in the browser html view, and then change your program to give that output. It may take a few iterations, but you can see the effects of program changes immediately in your browser html view window (You can even leave the file's html view open and click on the "refresh" icon to see the effects of changes in its source.)

If there is something that you can't really figure out, there's always the html reference to "fall back on."

Have fun.

Regards,

Dave

Footnotes:

"Ya gotta have a plan."

davekw7x
--- on gidforums.com

-----------------

"The best-laid schemes o' mice an' men
Gang aft agley"

Robert Burns
---To A Mouse, On Turning Her Up In Her Nest With The Plough

-----------------

"We can face our problem.
We can arrange such facts as we have with order and method."

Hercule Poirot
--- in Murder on the Orient Express
Last edited by davekw7x : 10-Jun-2006 at 11:25.
  #3  
Old 11-Jun-2006, 02:20
Johnny Johnny is offline
New Member
 
Join Date: May 2006
Posts: 27
Johnny is on a distinguished road

Re: convert C to HTML!


Aswell as replacing less than/more than characters you could replace quote marks (&quot, maybe in future add syntax highlighting, don't worry about this yet.

Like davekw7x said put together a plan, write your notes and ideas down in notepad, doesn't matter if they are not neat, but just make sure they are readable and understandable. Once you have a rough idea of where you want your project to go start to write it up in pseudo-code.
 
 

Recent GIDBlogObservations of Iraq by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
including html help last time! dopee MySQL / PHP Forum 3 14-Feb-2005 04:08
working with html HELP dopee MySQL / PHP Forum 10 18-Jan-2005 04:31
saving html text dopee MySQL / PHP Forum 1 17-Jan-2005 04:15
What should I use? XHTML 1.0 or HTML 4.01 Strict? retxedz Web Design Forum 0 24-Dec-2004 15:56

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 11:21.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.