Re: read writte to file



Carramba wrote:
>
> oh man thats rocks! thanx,
> I jus have few questions and I hope you don't
> mind to answer them
>
> On Tue, 07 Jun 2005 23:04:11 +0200,
> pete <pfiland@xxxxxxxxxxxxxx> wrote:

> > int cK, rc;

> > cK = getchar();

> > getchar();
> why do you double getchar(); ?

To eat the '\n' from the Enter key.
Note that cK is of type int and not char,
to match the return type of getchar.

> > fputs("Type a name: ", stdout);
> > fflush(stdout);
> > rc = scanf("%" xstr(a_LEN) "[^\n]%*[^\n]", a_Namn);
>
> don't realy understand what are you doing here
> ( in line above )? I se
> that you are reading input, but could you explaine more?

Zorna Cutura explained it pretty good.
The idea, is to convert text lines into strings.
Text files and streams are made of lines.
A line is like a string, except that a line is
teminated by a '\n' character,
and a string is terminated by a '\0' character.

> > if (!feof(stdin)) {
> > getchar();
> > }
> > if (rc != 1) {
> > *a_Namn = '\0';
> > }
> > fputs("Type cd titel: ", stdout);

There should be
fflush(stdout);
after that fputs.


--
pete
.



Relevant Pages

  • Re: Ex 7-5
    ... value in addition to the full character set. ... The value returned by getchar() is definitely of type int. ... That value might or might not be within the range of type char (i.e., ...
    (comp.lang.c)
  • [TOMOYO #15 3/8] Common functions for TOMOYO Linux.
    ... This file contains common functions (e.g. policy I/O, pattern matching). ... Since TOMOYO Linux is a name based access control, ... TOMOYO Linux's string manipulation functions make reviewers feel crazy, ... the Linux kernel accepts all characters but NUL character ...
    (Linux-Kernel)
  • RfD: Escaped Strings version 4
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... as an escape character for the entry of characters that cannot be ... \b BS (backspace, ASCII 8) ...
    (comp.lang.forth)
  • RfD: Escaped Strings version 4
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... as an escape character for the entry of characters that cannot be ... \b BS (backspace, ASCII 8) ...
    (comp.lang.forth)
  • Re: RfD: Escaped Strings
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... \b BS (backspace, ASCII 8) ... \ ** escapes to characters much as C does. ...
    (comp.lang.forth)

Loading