Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting smileys instead of alphabets 1

Status
Not open for further replies.

saurabh21

Programmer
Sep 5, 2005
1
IN
Hi,
I'm trying to read from a file and then based on certain conditions filtering it into another file.But what i get in the file and the console are some unreadable characters.Could anyone tell me where am i going wrong? My code is this :
Code:
char c[100];
FILE *fpt, *reqfpt;	
fpt = fopen("Header.dat","r");
reqfpt = fopen("wrResult.dat","w");

while(c[i]=getc(fpt)!='\r')
	  {
		printf("%c",c[i]);
		i++;
	  }

Thanks,
Saurabh
 
Try
Code:
while((c[i]=getc(fpt))!='\r')
 
There are a number of major questions around your code.

1) Why are you using the char array - do you want the read bytes available later?
2) Do you really mean to read up to the first CR? If so what happens when there's no CR in the file?
3) What happens if the first CR is > 100 chars into the file
4) You open an output file but print to stdout - is this what you mean?
5) You don't test whether the fileopens work - nit picking I know but...

It looks like you're trying to remove CRs from the file (as in DOS -> Unix transforms). If this is the case
Code:
int c;
FILE *fpIn, *fpOut;

if ( ( fpIn = fopen ( "Header.dat","r") ) == NULL )
  {
  fprintf ( stderr, "Unable to open Header.dat for reading\n" );
  exit (-1);
  }

if ( ( fpOut = fopen ("wrResult.dat","w") ) == NULL )
  {
  fprintf ( stderr, "Unable to open wrResult.dat for writing\n" );
  exit (-1);
  }

while ( ( c = fgetc ( fpIn ) ) != EOF )
  if ( c != '\r' )
    fputc ( c, fpOut );

fclose ( fpIn );
fclose ( fpOut );


Columb Healy
 
Assuming file type is .dat - no readable text is inside. In that case you will get all possible smileys of course. Try to use "<%d>" instead of "%c".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top