A
antonaras
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
#include
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 (pFile);
}
return 0;
}
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!
and i'm trying to read from a file character by character and output
the result on the console.
This is my code:::
#include
#include
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 (pFile);
}
return 0;
}
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!