I want to write a C program that can parse input and give corresponding output like xml or html. Can someone also give a SMALL example as to how this works.
I want to write a C program that can parse input and give corresponding output like xml or html. Can someone also give a SMALL example as to how this works.
Asking the right question is sometimes more important than knowing the answer.
Please read the FAQ
C Reference Card (A MUST!)
Pointers and Memory
The Essentials
CString lib
What's your input look like?
There's only the usual bunch of functions to work with, fgetc(), fgets(), fread(), fscanf() etc etc.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
like perhaps i want this:
the user inputs the <p>tag when ever he wants a new line written to a file like
FILE *fp;
fp=fopen("file.txt","a");
RECIEVE INPUT
PARSE FOR <p>'s
OUTPUT TO fp
fclose(fp);
something like that, but I will define the tags (library of tags) later
Asking the right question is sometimes more important than knowing the answer.
Please read the FAQ
C Reference Card (A MUST!)
Pointers and Memory
The Essentials
CString lib
Your output file is what exactly? Text? HTML? If it's just HTML, simply directly send the output. It's up to them to make sure their tags are correct. You can always set up "matched" vs "non-matched" or "paired" vs "non-paired" tags and count up the total when done saying "You have three unmatched <B> tags."Originally posted by Lynux-Penguin
like perhaps i want this:
the user inputs the <p>tag when ever he wants a new line written to a file like
FILE *fp;
fp=fopen("file.txt","a");
RECIEVE INPUT
PARSE FOR <p>'s
OUTPUT TO fp
fclose(fp);
something like that, but I will define the tags (library of tags) later
I don't understand what your problem is. Don't you know how to use basic file input? Do you not know how to read input from a user, or what exactly is your problem?
Quzah.
Hope is the first step on the road to disappointment.
I didn't want to post code
basically
I want the input from a user to be parsed for tags
like webbrowsers do for HTML or some XML parsers, I can't find any example code anywhere, I am just curious as to the key behind parsers so that I may take advantage of it.
Asking the right question is sometimes more important than knowing the answer.
Please read the FAQ
C Reference Card (A MUST!)
Pointers and Memory
The Essentials
CString lib
Um... It's not difficult:
Vola. Parser.Code:while( c != EOF ) { while( (c=fgetc(stdin))!= '<') ) { if ( c != EOF ) buffer[x++]=c; } while( (c=fgetc(stdin))!= '>') ) { if ( c != EOF ) tag[y++] = c; } }
Quzah.
Hope is the first step on the road to disappointment.
thanks, that helps a lot
but, when is EOF reached by the user?
is it when the return key is striked or what?
Asking the right question is sometimes more important than knowing the answer.
Please read the FAQ
C Reference Card (A MUST!)
Pointers and Memory
The Essentials
CString lib
It's EOF. Typically this is CTRL+Z or CTRL+D or something similar, OS dependant. You could subsitute EOF for whatever you wanted.
Quzah.
Hope is the first step on the road to disappointment.
thanks again!
Asking the right question is sometimes more important than knowing the answer.
Please read the FAQ
C Reference Card (A MUST!)
Pointers and Memory
The Essentials
CString lib