Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 18th, 2006, 2:22 PM   #1
dchankhour
Newbie
 
Join Date: Jan 2006
Location: Poway, CA
Posts: 13
Rep Power: 0 dchankhour is on a distinguished road
beginner question

how do i write a function that outputs a newline character, and output the newline character throught fputc.
dchankhour is offline   Reply With Quote
Old Jan 18th, 2006, 2:28 PM   #2
para
Programmer
 
Join Date: Dec 2005
Posts: 65
Rep Power: 3 para is on a distinguished road
Quote:
NAME
fputc, fputs, putc, putchar, puts - output of characters and strings

SYNOPSIS
#include <stdio.h>

int fputc(int c, FILE *stream);
int fputs(const char *s, FILE *stream);
int putc(int c, FILE *stream);
int putchar(int c);
int puts(const char *s);

DESCRIPTION
fputc() writes the character c, cast to an unsigned char, to stream.

fputs() writes the string s to stream, without its trailing '\0'.

putc() is equivalent to fputc() except that it may be implemented as a macro which evaluates stream more than once.

putchar(c); is equivalent to putc(c,stdout).

puts() writes the string s and a trailing newline to stdout.

Calls to the functions described here can be mixed with each other and with calls to other output functions from the stdio library for the same output stream.

For non-locking counterparts, see unlocked_stdio(3).

RETURN VALUE
fputc(), putc() and putchar() return the character written as an unsigned char cast to an int or EOF on error.

puts() and fputs() return a non-negative number on success, or EOF on error.


CONFORMING TO
ANSI-C, POSIX.1
If you want to write a line feed with fputc()...
fputc('\n', stdout);
A more common way is..
printf("\n");
or
fprintf(stdout, "\n");
para is offline   Reply With Quote
Old Jan 18th, 2006, 4:05 PM   #3
Justin Case
Newbie
 
Justin Case's Avatar
 
Join Date: Aug 2005
Location: In the void between my two monitors...
Posts: 15
Rep Power: 0 Justin Case is on a distinguished road
Send a message via AIM to Justin Case
fputc('\n', stdout); works... if you must use fputc.
__________________
... after all, we're all alike.
Justin Case is offline   Reply With Quote
Old Jan 18th, 2006, 5:11 PM   #4
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
I'm curious, why do you want to do it with fputc?
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Jan 18th, 2006, 6:10 PM   #5
para
Programmer
 
Join Date: Dec 2005
Posts: 65
Rep Power: 3 para is on a distinguished road
Quote:
Originally Posted by nnxion
I'm curious, why do you want to do it with fputc?
He didn't explicitly say he wanted the output to be stdout, he may be using a pipe or file. Just a guess.
para is offline   Reply With Quote
Old Jan 18th, 2006, 8:39 PM   #6
dchankhour
Newbie
 
Join Date: Jan 2006
Location: Poway, CA
Posts: 13
Rep Power: 0 dchankhour is on a distinguished road
i just thought fputc is the simpliest way to do it
dchankhour is offline   Reply With Quote
Old Jan 18th, 2006, 9:11 PM   #7
Justin Case
Newbie
 
Justin Case's Avatar
 
Join Date: Aug 2005
Location: In the void between my two monitors...
Posts: 15
Rep Power: 0 Justin Case is on a distinguished road
Send a message via AIM to Justin Case
It depends on where you want to output it to, if you want to output it to standard output (console), the simplest way to do it is with something like printf("\n"); or putchar('\n');.
__________________
... after all, we're all alike.
Justin Case is offline   Reply With Quote
Old Jan 18th, 2006, 9:12 PM   #8
Justin Case
Newbie
 
Justin Case's Avatar
 
Join Date: Aug 2005
Location: In the void between my two monitors...
Posts: 15
Rep Power: 0 Justin Case is on a distinguished road
Send a message via AIM to Justin Case
oh and... next time you post... please make the title of the thread a bit more descriptive of the problem "fputc problem" or something like that would be great, thanks.
__________________
... after all, we're all alike.
Justin Case is offline   Reply With Quote
Old Jan 18th, 2006, 9:33 PM   #9
dchankhour
Newbie
 
Join Date: Jan 2006
Location: Poway, CA
Posts: 13
Rep Power: 0 dchankhour is on a distinguished road
alright , i will do my best
and thanks for the help everybody
dchankhour is offline   Reply With Quote
Old Jan 19th, 2006, 7:55 AM   #10
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Yes do read the "How to post a question" thread, at the top of the forum.
If you can use C++, then you will find using std::cout a better alternative.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:43 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC