Syntax question

D

deppy_3

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();
 
R

Richard Heathfield

(e-mail address removed) 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.
 
C

Clever Monkey

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?
 
D

deppy_3

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();
 
C

Coos Haak

Op 10 Jul 2006 09:41:11 -0700 schreef (e-mail address removed):
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
 
C

Clever Monkey

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.
 
D

deppy_3

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.
 
W

Walter Roberson

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);
 
C

Clever Monkey

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().
 
A

Andrew Poelstra

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?
 
J

John Bode

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
 
K

Keith Thompson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,181
Messages
2,570,970
Members
47,537
Latest member
BellCorone

Latest Threads

Top