LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-22-2004, 02:45 AM   #1
joakim12
Member
 
Registered: Nov 2003
Location: Estonia
Distribution: Ubuntu 18.04
Posts: 82

Rep: Reputation: 15
char chr(int keycode) ???


Is there a function in GlibC that can do it for me?

char FunctionName(int keycode)

The problem is that I read from a file with:

int fgetc (FILE * stream);

and i want to append that char to a string:

char * strcat ( char * dest, const char * src );

but the:

char * fgets (char * string , int num , FILE * stream);

does not work correctly. It reads in something completely different on certain cases.

For example the string in a textfile:

P6hja-Ameerika

Will be printed with mvprintw and something like that (not exactly):

P6hja-Ameeri^A^Bka

And some other words cause different phenomena characters.
I don't know why but I thought to give a try to fgetc. Or maybe someone knows the deal with fgets. I wanna read from a file char-by-char to know exactly what I'm reading.

Leho Pärnapuu

Last edited by joakim12; 04-22-2004 at 04:23 AM.
 
Old 04-22-2004, 03:59 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
To read a file a char at a time I'd write something like this (you were right to use fgetc()):

Code:
// Assume buffer is large enough to hold the file and fp is already open
void read_file(char *buffer, FILE *fp)
{
  int ch;
  char *b = buffer;

  while((ch = fgetc(fp)) != EOF)
    *b++ = ch;
  *b = '\0';  // NULL-terminate if you want to use the buffer as a string
}

Last edited by itsme86; 04-22-2004 at 04:00 AM.
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C programming int to char conversion paranoid times Programming 15 03-17-2005 11:06 PM
char to int: a twist Guru3 Programming 5 12-05-2004 08:49 AM
Converting int value to char liguorir Programming 8 05-23-2004 07:21 PM
int(char(254)) becomes kalleanka Programming 2 02-17-2004 03:35 PM
int, long in char * marek Programming 10 09-01-2003 10:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration