By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,091 Members | 1,546 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,091 IT Pros & Developers. It's quick & easy.

Syntax question

P: n/a
Hi!
The syntax of fputs() is similar with the syntax of fgets();
For example
if we have:fgets(str,maxlen,stdin)
which is the syntax of the fputs();

Jul 10 '06 #1
Share this Question
Share on Google+
11 Replies


P: n/a
de*****@hotmail.com said:
Hi!
The syntax of fputs() is similar with the syntax of fgets();
For example
if we have:fgets(str,maxlen,stdin)
which is the syntax of the fputs();
See page 247 of "The C Programming Language", 2nd edition, by Kernighan and
Ritchie.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jul 10 '06 #2

P: n/a
de*****@hotmail.com wrote:
Hi!
The syntax of fputs() is similar with the syntax of fgets();
For example
if we have:fgets(str,maxlen,stdin)
which is the syntax of the fputs();
int fputs(const char *s, FILE *stream);

The function accesses characters from C string s and writes them to the
output stream stream. The function does not write the terminating null
character. It returns a nonnegative value if it has not set the error
indicator; otherwise, it returns EOF.

stdin: #define stdin <pointer to FILE rvalue>

The macro yields a pointer to the object that controls the standard
input stream.

Writing such a string to stdin may not make a whole lot of sense.

Perhaps rephrase your question?
Jul 10 '06 #3

P: n/a
Perhaps rephrase your question?

When we have for example:
printf("Dwste to onoma sas");
gets(name);

In which way can i see in the screen the name that i have inserted;
One way is for example puts(name). Right;
How can i do it this with the fputs();

Jul 10 '06 #4

P: n/a
Op 10 Jul 2006 09:41:11 -0700 schreef de*****@hotmail.com:
Hi!
The syntax of fputs() is similar with the syntax of fgets();
For example
if we have:fgets(str,maxlen,stdin)
which is the syntax of the fputs();
man fputs
--
Coos
Jul 10 '06 #5

P: n/a
de*****@hotmail.com wrote:
>Perhaps rephrase your question?

When we have for example:
printf("Dwste to onoma sas");
gets(name);

In which way can i see in the screen the name that i have inserted;
One way is for example puts(name). Right;
How can i do it this with the fputs();
I don't think stdio works the way I think you say it does, at least not
portably. Then again, I may have an incomplete understanding of what
you are trying to achieve. Perhaps post some code that compiles cleanly
that shows your "one way" you know works.
Jul 10 '06 #6

P: n/a
>Perhaps post some code that compiles cleanly
that shows your "one way" you know works.

Let's see a small code with puts.

#include<stdio.h>

char *messages[5]={"This","is","a","short","message."};

main()
{
int x;
for(x=0;x<5;x++)
puts(messages[x]);

puts("And this is the end!");

return 0;
}

Having seen this programm can you tell me how can i may it with
fputs();I hope to cover you with this small programm.

Jul 10 '06 #7

P: n/a
In article <11**********************@h48g2000cwc.googlegroups .com>,
<de*****@hotmail.comwrote:
>When we have for example:
printf("Dwste to onoma sas");
gets(name);
In which way can i see in the screen the name that i have inserted;
One way is for example puts(name). Right;
How can i do it this with the fputs();
fputs(name, stdout);

--
I was very young in those days, but I was also rather dim.
-- Christopher Priest
Jul 10 '06 #8

P: n/a
de*****@hotmail.com wrote:
>Perhaps post some code that compiles cleanly
that shows your "one way" you know works.


Let's see a small code with puts.

#include<stdio.h>

char *messages[5]={"This","is","a","short","message."};

main()
{
int x;
for(x=0;x<5;x++)
puts(messages[x]);

puts("And this is the end!");

return 0;
}

Having seen this programm can you tell me how can i may it with
fputs();I hope to cover you with this small programm.
These lines are _nearly_ equivalent:

fputs(messages[x], stdout);
[...]
fputs("And this is the end!", stdout);

Though you will note that there is no implicit newline sent to stdout
via fputs().
Jul 10 '06 #9

P: n/a
On 2006-07-10, de*****@hotmail.com <de*****@hotmail.comwrote:
>Perhaps rephrase your question?

When we have for example:
printf("Dwste to onoma sas");
gets(name);

In which way can i see in the screen the name that i have inserted;
One way is for example puts(name). Right;
How can i do it this with the fputs();
How did you make `name' an infinite array?

--
Andrew Poelstra <http://www.wpsoftware.net/projects/>
To email me, use "apoelstra" at the above domain.
"You people hate mathematics." -- James Harris
Jul 10 '06 #10

P: n/a

de*****@hotmail.com wrote:
Perhaps rephrase your question?

When we have for example:
printf("Dwste to onoma sas");
gets(name);
*Please* don't ever use gets(); it will introduce a point of failure in
your code (specifically, it will make your code vulnerable to buffer
overruns, which is a common security hole). Use fgets() instead:

fgets(name, sizeof name, stdin); // buffer, buffer size, input
stream

Seriously, pretend you never knew gets() ever existed.
>
In which way can i see in the screen the name that i have inserted;
One way is for example puts(name). Right;
How can i do it this with the fputs();
fputs(name, stdout); // or some other output stream

Jul 10 '06 #11

P: n/a
de*****@hotmail.com writes:
The syntax of fputs() is similar with the syntax of fgets();
For example
if we have:fgets(str,maxlen,stdin)
which is the syntax of the fputs();
The syntax of a call to fputs() is the same as the syntax of any
function call. But you probably want to know more than just the
syntax; you want to know how to use it.

You should have some form of documentation for the functions in the C
standard library. On some systems, the "man" command will show you
this documentation. On others, there may be something called a "help"
system, or possibly an "info" command.

If you're learning to program in C, you should have a text book; look
up "fputs" in its index. If you don't have a text book, you need to
get one. One of the best tutorials is K&R2 (Kernighan & Ritchie, _The
C Programming Language_, 2nd edition).

I have a number of such resources myself; if I didn't, the first thing
I'd try is a Goole search for "fputs". (Ignore the references to PHP;
that's a different language, and apparently it has a function with the
same name.)

Your question is a very elementary one. If you have some resource
where you can look up things like this, you won't need to post such
questions here. If you don't have such a resource, it's going to be
very difficult to learn C.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 10 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.