Wabt to change the output port address from "printf" 
Author Message
 Wabt to change the output port address from "printf"

Does anyone know how to change the output port address from the function

"printf" in ANSI C?
Someone told me that I can do it by editing the header file "STDIO.H",
is that right?
And how can I do it?
Please tell me, thank you!

Marco



Tue, 22 Aug 2000 03:00:00 GMT  
 Wabt to change the output port address from "printf"

Quote:

>Does anyone know how to change the output port address from the function
>"printf" in ANSI C?

The concept of ANSI C does not know the term "port address".

Quote:
>Someone told me that I can do it by editing the header file "STDIO.H",
>is that right?

No, this is definitely bogus.  You  must  never  edit  system  header
files.

Quote:
>And how can I do it?

Probably you should use fopen() to open  an  output  stream  and  use
fprintf() instead of printf() [which uses the standard output sstream
"stdout"].

Wolfgang Denk



Research is what I'm doing when I don't know what I'm doing.
                                                 -- Wernher von Braun



Tue, 22 Aug 2000 03:00:00 GMT  
 Wabt to change the output port address from "printf"

Quote:

> Does anyone know how to change the output port address from the function
> "printf" in ANSI C?

I don't quite know what an "output port address" is in the context of
printf()

Quote:
> Someone told me that I can do it by editing the header file "STDIO.H",
> is that right?

Editing the standard headers is a *really* bad idea, and is unlikely
to achieve what you want.  If you edit the headers, the definitions in
them won't match up to what is actually in the standard libraries, and
things may stop working.

Quote:
> And how can I do it?

If you  want output from  printf() to go somewhere  else there are two
approaches.  One is to use OS facilities, such as Unix plumbing (< > |
and so on).  The other is to  open appropriate files using fopen() and
then print to them using fprintf().  Your operating system may support
accessing hardware devices through special files.

Without knowing exactly what you are trying to achieve, I can't think
of anything else to suggest.

--

            http://www.tardis.ed.ac.uk/~broonie/
            http://www.ed.ac.uk/~filmsoc/



Tue, 22 Aug 2000 03:00:00 GMT  
 Wabt to change the output port address from "printf"



Quote:
>Does anyone know how to change the output port address from the function

>"printf" in ANSI C?

What do you mean by "the output port address"? There is nothing like this
defined by C. You can redirect stdout to a different file or device using
freopen().

Quote:
>Someone told me that I can do it by editing the header file "STDIO.H",
>is that right?

No. You should never touch header files. All you are likely to do is break
the compiler for all of your programs.

Quote:
>And how can I do it?

Unfortunately you haven't made it clear what you want to do. Perhaps an
example would help.

--
-----------------------------------------


-----------------------------------------



Tue, 22 Aug 2000 03:00:00 GMT  
 Wabt to change the output port address from "printf"

Quote:

> Does anyone know how to change the output port address from the function

> "printf" in ANSI C?
> Someone told me that I can do it by editing the header file "STDIO.H",
> is that right?

No.

Never, ever, edit the standard header files.

Quote:
> And how can I do it?

If you use fprintf() instead of printf() then you can output data
wherever you want to.

eg.

foo()
{
  FILE *out;

  if (output_to_console) {
     out = stdout;                   /* print to stdout */
  }
  else {
     out = fopen("textfile","w");    /* print to a file */
  }

  /* use fprintf() for all output */

  fprintf(out, "Hello, world!\n");

  if (!output_to_console) {  /* If it's a text file we need to close it
*/
    fclose(out);
  }

Quote:
}

If your operating system supports it you can output to
printers, serial ports etc. as well. You need to ask about
this in a newsgroup specific to your computer though...

--
<\___/>
/ O O \
\_____/ FTB.



Thu, 24 Aug 2000 03:00:00 GMT  
 Wabt to change the output port address from "printf"

: Does anyone know how to change the output port address from the function

: "printf" in ANSI C?
: Someone told me that I can do it by editing the header file "STDIO.H",
: is that right?
: And how can I do it?
: Please tell me, thank you!

You are MUCH better off opening the desired port as a stream (many can be
opened with fopen()) and using fprintf() to write to it.  Do NOT try to
alter the behavior of printf().

Further, you cannot alter the behavior of printf() by editing the header
file!

--
================================================

  http://www.*-*-*.com/
================================================
READ THE FAQ for more information:
 C-FAQ ftp sites: ftp://ftp.eskimo.com
               or ftp://rtfm.mit.edu
 Hypertext C-FAQ: http://www.*-*-*.com/ ~scs/C-faq/top.html

The money spent on an {*filter*},as any woman may find out,
can better be spent on other things,
like taking the kids to an amusment park, or on vacation.



Thu, 24 Aug 2000 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. printf("%x",string_buffer); - Output question

2. printf("%d",1.0/3*3)

3. printf("/033E")

4. printf("%g") to 3 sig figs

5. "implicit declaration of function printf"

6. Behaviour of printf("[%.0g]",1.0)

7. "printf()" hangs machine

8. C source code for "printf"

9. "printf" question

10. printf("%x",float) is ZERO??

11. printf("%")

12. how does printf("%#06x", 0x80) look?

 

 
Powered by phpBB® Forum Software