|
Hi i'm new to c++
and i'm trying to read from a file character by character and output the result on the console.
This is my code:::
#include <stdio.h>
#include<iostream.h>
int in_tags(FILE *pFile)
{
char t;
cout<<"in tags";
t=getc(pFile);
cout<<t;
while="" (t="getc(pFile)!='">')
{
cout<<t;
}
="" return="" 0;
}
int="" main="" ()
{
="" file="" *="" pfile;
="" char="" c;
="" bool="" tag;
="" pfile="fopen("example.txt","r");
" if="" (pfile="=NULL)" perror="" ("error="" opening="" file");
="" else
="" {
="" do="" c="getc" (pfile);
="" cout<<c;
="" if(c="='<')
" tag="in_tags(pFile);
" }="" while="" (c="" !="EOF);
" fclose=""
="" 0;
}
the="" output::
ok<in="" tagsi☺☺☺☺☺ok="" ok="" ok<in="" tagsi☺☺☺☺☺<in="" press="" any="" key
to="" continue
the="" file::
ok<inside="">ok ok ok<inside><inside>ok ok ok ok
The output that i get from the main program is ok
but when are coming from the function within the while loop
the caracters are lost and i get symbols.
I hope i'm clear enough but i don't think so but in case you know how to help me pls reply as this is for a project that i'm doing for college
thanks in advance!
|
|
|
|
|
Hello antonaras
Can you plz explain what is while (t=getc(pFile)!='>')
You should change your code like
while (getc(pFile) !='>')
Check it. It should work. I think due to wrong expression, you are going in an infinite loop.
Am i right?
Gool luck.
We Believe in Excellence
|
|
|
|
|
Aqueel thanks for the reply
i'll get more specific
what i'm trying to do is read an html code and clean the text from the tags(<>)
in function in_tags i want to process the html code to get understant things like color type font and so on.
in main i get the text if i get a character '<' i call function in_tags to process the tags part of the file. so i use while (t=getc(pFile)!='>') to terminate the function because the text is no longer in tags!
i try to outout on the console the text presented in tags in that while loop to make sure i'm in the right path but it seems that i'm not because in
while (t=getc(pFile)!='>')
cout<
|
|
|
|
|
Hey Aqueel i worked on what u said
u where right the problem is that i can't do this
while (t=getc(pFile)!='>')
i first need to get the character t=getc(pFile)
and than change the while loop to while(t!='>')
now is working thanks a lot u r the best cheers
|
|
|
|
|
antonaras_marcou wrote: the problem is that i can't do this
while (t=getc(pFile)!='>')
You can if you'd just add another pair of parenthesis:
while ((t = getc(pFile)) != '>') Breaking this statement into two separate statements is a better idea, however.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
you r right!!
i've spend hours trying to find what is wrong and that's it
2 more parenthesis!!
thanks for helping DavidCrow
|
|
|
|
|
antonaras_marcou wrote:
what i'm trying to do is read an html code and clean the text from the tags(<>)
Are you aware of Mr.Alok's product?
check^
VuNic
|
|
|
|
|
Thanks VuNic i've been looking for something like this for weeks now and i couldn't find anything helpfull enough.
This looks promising i hope i can understand the code and use it for my needs?
Thanks again appreciate
p.s If i have any problem using it i'll post a new message.
|
|
|
|
|
antonaras_marcou wrote: p.s If i have any problem using it i'll post a new message.
you are most welcome.
VuNic
|
|
|
|
|
he is assigning at the same time the variable t with the return of getc(pFile) . this is correct code.
don't confuse between operator = and operator == ...
|
|
|
|
|
Thanks for the reply v2.0
your saying that t=getc(pFile)is correct and it is the problem i had is when i include function getc in a while loop thats when the whole thing crashes.
Thangs again for the reply
|
|
|
|
|
Hello antonaras
I wanted to say that you can not do like that is loop. Actually you are not getting input again in while loop.
Please change your code with following after cout<<"in tags";
t=getc(pFile);<br />
while (t!='>')<br />
{<br />
cout<<t;<br />
t = getc(pFile);<br />
}
It should work. Dont hasitate to ask in case of any problem.
Good luck.
We Believe in Excellence
|
|
|
|
|
You can always rank helpful replies(on bottom right).
Regards
We Believe in Excellence
|
|
|
|
|
#include <iostream>
#inlcude <fstream>
#include <iterator>
#include <algorithm>
using namespace std;
int main ()
{
ifstream ifs("C:\\a.txt");
ifs >> noskipws; // We want white space.
copy(istream_iterator<char>(ifs), istream_iterator<char>(), ostream_iterator<char>(cout));
}
Steve
-- modified at 7:13 Wednesday 8th March, 2006
|
|
|
|
|
Hi,
I know virtual and heap memory use paged memory, but what is un-paged memory? Is it local and global variables?
Neil
-- modified at 4:22 Wednesday 8th March, 2006
|
|
|
|
|
The unpaged pool is where memory is allocated by the kernel and drivers which isn't paged out; it's always available without having to load it from disc. It is used to store information which must be instantly available such as data needed to service interrupts as such. It is of no real interest application developers.
Steve
|
|
|
|
|
Thanks Stephen.
What about local and global memory? Is all types of variables Virtual, ie paged?
Neil
|
|
|
|
|
By local and global memory I assume you referring to the LocalAlloc and GlobalAlloc APIs. These two APIs are vestiges of the old 16 bit days - In modern Windows these are just allocated memory from a normal heap. Or perhaps you are referring to local vs global variables - A local variable is a variable that only exists in a specific scope and is no longer valid when that scope exits.
Steve
|
|
|
|
|
can u just me any book regarding the explanation
Thanx in advance
never say die
|
|
|
|
|
Sorry, I don't know of any such books.
Steve
|
|
|
|
|
hello all,
I want to know how to add tooltips to the hover buttons.
I got this hover button class from one codeproject article.even they gave code for adding tool tips.but it is not working in my project.
So plz help me to add tooltips to hover buttons.Its very urgent.
thanks in advance
cheers
sangeet
-- modified at 4:15 Wednesday 8th March, 2006
|
|
|
|
|
ramyasangeet wrote: I got this hover button class from one codeproject article
You should ask this question to the author of the article.
Nibu thomas
Software Developer
|
|
|
|
|
thanks for ur reply
cheers
sangeet
|
|
|
|
|
hi,
I have downloaded "Magnifying Glass" by "Alex FR" ,application from codeproject.How do we activate the .exe with hokey.........When it in systemtray.
Thanks before
James rocky
|
|
|
|
|
RockyJames wrote: How do we activate the .exe with hokey
Create a shortcut to the executable by right-clicking on it and selecting "Create Shortcut". Move the shortcut to the desktop. Right-click on the new shortcut and select "Properties". On the "Shortcut" tab you can specify a hotkey combination for it.
Best regards
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|