473,388 Members | 1,340 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Difference between various functions

SDZ
Could somebody explain in simple forms, what is/are the difference(s) between

- scanf and sscanf and ssscanf
- printf and sprintf
- open and fopen

Thanks in advance,
SDZ
Nov 14 '05 #1
18 1739
SDZ <sa******@hotmail.com> scribbled the following:
Could somebody explain in simple forms, what is/are the difference(s) between - scanf and sscanf and ssscanf
scanf reads from stdin, sscanf from a string. ssscanf doesn't exist.
- printf and sprintf
printf prints into stdout, sprintf into a string.
- open and fopen


open doesn't exist. fopen opens a file.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"It was, er, quite bookish."
- Horace Boothroyd
Nov 14 '05 #2
On 2004-06-14, Joona I Palaste <pa*****@cc.helsinki.fi> wrote:
SDZ <sa******@hotmail.com> scribbled the following:
Could somebody explain in simple forms, what is/are the difference(s) between

- scanf and sscanf and ssscanf


scanf reads from stdin, sscanf from a string. ssscanf doesn't exist.
- printf and sprintf


printf prints into stdout, sprintf into a string.
- open and fopen


open doesn't exist. fopen opens a file.


open is an UNIX system call for opening files. Not related to ISO C.

--
"Computers are useless. They can only give you answers"
- Pablo Picasso

[paulo-pereira dot perso at wanadoo dot fr]
Nov 14 '05 #3
SDZ wrote:

Could somebody explain in simple forms, what is/are the difference(s) between

- scanf and sscanf and ssscanf
- printf and sprintf
- open and fopen

What does your C textbook say? Learning C from random questions on
usenet is a bad idea and no substitute for proper study. You are wasting
your time and ours.


Brian Rodenborn
Nov 14 '05 #4
On Mon, 14 Jun 2004 04:47:13 -0700, SDZ wrote:
Could somebody explain in simple forms, what is/are the difference(s) between

- scanf and sscanf and ssscanf
- printf and sprintf
- open and fopen

Thanks in advance,
SDZ

int scanf(const char *format, ...);
int sscanf(const char *str, const char *format, ...);
(never heard of ssscanf)
int printf(const char *format, ...);
int sprintf(char *str, const char *format, ...);

int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
FILE *fopen(const char *path, const char *mode);

You can easily see some docs for these in section 2 and 3
at e.g. http://netbsd.gw.com/cgi-bin/man-cgi

Nov 14 '05 #5
Nils O. Selåsdal <NO*@utel.no> scribbled the following:
On Mon, 14 Jun 2004 04:47:13 -0700, SDZ wrote:
Could somebody explain in simple forms, what is/are the difference(s) between
- open and fopen
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
FILE *fopen(const char *path, const char *mode);


Wait, wait. Two distinct functions with the same name aren't possible in
ISO-compliant C, even if they use different parameters. Does the POSIX
standard actually require the compiler to use non-standard extensions?

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Normal is what everyone else is, and you're not."
- Dr. Tolian Soran
Nov 14 '05 #6
Joona I Palaste <pa*****@cc.helsinki.fi> writes:
Nils O. Selåsdal <NO*@utel.no> scribbled the following:
On Mon, 14 Jun 2004 04:47:13 -0700, SDZ wrote:
Could somebody explain in simple forms, what is/are the difference(s) between
- open and fopen

int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);


Wait, wait. Two distinct functions with the same name aren't possible in
ISO-compliant C, even if they use different parameters. Does the POSIX
standard actually require the compiler to use non-standard extensions?


Well, the actuall prototype should be

int open(const char *, int, ...);

or, as commonly used in documentation

int open(const char *path, int oflag, /* mode_t mode */);

and that C handles quite well using <stdarg.h> type of functions.

The same way you handle fprintf(...) type of functions.

Bye, Dragan

--
Dragan Cvetkovic,

To be or not to be is true. G. Boole No it isn't. L. E. J. Brouwer

!!! Sender/From address is bogus. Use reply-to one !!!
Nov 14 '05 #7
Joona I Palaste wrote:
Nils O. Selåsdal <NO*@utel.no> scribbled the following:
On Mon, 14 Jun 2004 04:47:13 -0700, SDZ wrote:
Could somebody explain in simple forms, what is/are the difference(s) between
- open and fopen


int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
FILE *fopen(const char *path, const char *mode);



Wait, wait. Two distinct functions with the same name aren't possible in
ISO-compliant C, even if they use different parameters. Does the POSIX
standard actually require the compiler to use non-standard extensions?


<OT> I think

int open(const char *path, int flags, ...);

is acceptable. </OT>

--
Er*********@sun.com

Nov 14 '05 #8
In article <ca**********@oravannahka.helsinki.fi>,
Joona I Palaste <pa*****@cc.helsinki.fi> wrote:
Nils O. Selåsdal <NO*@utel.no> scribbled the following:
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
Wait, wait. Two distinct functions with the same name aren't possible in
ISO-compliant C, even if they use different parameters.
It is possible if it can be implemented as a function with a variable
argument list, like this:

| #if defined(__STDC__)
|
| extern int fcntl(int, int, ...);
| extern int open(const char *, int, ...);

The open() function only needs to look at the third argument (mode) if
a certain bit (O_CREAT) is set in the second argument (flags).
Does the POSIX
standard actually require the compiler to use non-standard extensions?


No non-standard extensions are required.

--
Göran Larsson http://www.mitt-eget.com/
Nov 14 '05 #9
Joona I Palaste <pa*****@cc.helsinki.fi> writes:
Nils O. Selåsdal <NO*@utel.no> scribbled the following:
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);


Wait, wait. Two distinct functions with the same name aren't possible in
ISO-compliant C, even if they use different parameters. Does the POSIX
standard actually require the compiler to use non-standard extensions?


No. Typically open() is actually prototyped as
int open(const char *, int, ...);
--
"In My Egotistical Opinion, most people's C programs should be indented six
feet downward and covered with dirt." -- Blair P. Houghton
Nov 14 '05 #10
In article <ca**********@oravannahka.helsinki.fi>,
Joona I Palaste <pa*****@cc.helsinki.fi> wrote:
Nils O. Selåsdal <NO*@utel.no> scribbled the following:
On Mon, 14 Jun 2004 04:47:13 -0700, SDZ wrote:
Could somebody explain in simple forms, what is/are the difference(s)
between
- open and fopen

int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
FILE *fopen(const char *path, const char *mode);


Wait, wait. Two distinct functions with the same name aren't possible in
ISO-compliant C, even if they use different parameters. Does the POSIX
standard actually require the compiler to use non-standard extensions?


No, they require support for varargs functions, which is standard. The
actual prototype is:

int open(const char *pathname, int flags, ...);

But the only valid ways to call it correspond to the two prototypes that
Nils showed.

--
Barry Margolin, ba****@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Nov 14 '05 #11
Goran Larsson <ho*@invalid.invalid> scribbled the following
on comp.lang.c:
In article <ca**********@oravannahka.helsinki.fi>,
Joona I Palaste <pa*****@cc.helsinki.fi> wrote:
Nils O. Selåsdal <NO*@utel.no> scribbled the following:
> int open(const char *pathname, int flags);
> int open(const char *pathname, int flags, mode_t mode);
Wait, wait. Two distinct functions with the same name aren't possible in
ISO-compliant C, even if they use different parameters. It is possible if it can be implemented as a function with a variable
argument list, like this: | #if defined(__STDC__)
|
| extern int fcntl(int, int, ...);
| extern int open(const char *, int, ...); The open() function only needs to look at the third argument (mode) if
a certain bit (O_CREAT) is set in the second argument (flags). Does the POSIX
standard actually require the compiler to use non-standard extensions?

No non-standard extensions are required.


D'oh. I should have paid more attention to the parameter lists. Even
ISO standard C functions (printf, fprint, ...) work that way. Thanks to
all who replied.
One further question: Since AFAIK ISO standard C provides no way to
explicitly check the length of the varargs list, how does open() know
whether the "mode" argument was supplied or not? Or does it even need
to?

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"I said 'play as you've never played before', not 'play as IF you've never
played before'!"
- Andy Capp
Nov 14 '05 #12
On Mon, 14 Jun 2004, Joona I Palaste wrote:
One further question: Since AFAIK ISO standard C provides no way to
explicitly check the length of the varargs list, how does open() know
whether the "mode" argument was supplied or not? Or does it even need
to?


It doesn't need to know. The writers of the function quite
reasonably assume that if O_CREAT was specified, then the 3rd
argument was also passed. If it wasn't passed, whatever junk
is on the stack at that location will be used instead.

--
Rich Teer, SCNA, SCSA

President,
Rite Online Inc.

Voice: +1 (250) 979-1638
URL: http://www.rite-online.net
Nov 14 '05 #13
Rich Teer <ri*******@rite-group.com> scribbled the following
on comp.lang.c:
On Mon, 14 Jun 2004, Joona I Palaste wrote:
One further question: Since AFAIK ISO standard C provides no way to
explicitly check the length of the varargs list, how does open() know
whether the "mode" argument was supplied or not? Or does it even need
to?
It doesn't need to know. The writers of the function quite
reasonably assume that if O_CREAT was specified, then the 3rd
argument was also passed. If it wasn't passed, whatever junk
is on the stack at that location will be used instead.


All righty, thanks. I note that this behaviour is dependent on the
POSIX standard and the ISO C standard alone does not suffice to
guarantee it.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Nothing lasts forever - so why not destroy it now?"
- Quake
Nov 14 '05 #14
In article <Pi*******************************@zaphod.rite-online.net>,
Rich Teer <ri*******@rite-group.com> wrote:
If it wasn't passed, whatever junk
is on the stack at that location will be used instead.


| If it wasn't passed, whatever junk
| is in the implementation specific location[*] used to pass arguments
| will be used instead.
|
|[*] location includes memory, registers, disks, punched cards,
| mercury delay lines, ...

Writing about "the stack" in comp.lang.c is not recommended. :-/

--
Göran Larsson http://www.mitt-eget.com/
Nov 14 '05 #15
Joona I Palaste wrote:
The open() function only needs to look at the third argument (mode)
if a certain bit (O_CREAT) is set in the second argument (flags).
D'oh. I should have paid more attention to the parameter lists. Even
ISO standard C functions (printf, fprint, ...) work that way. Thanks
to all who replied.
One further question: Since AFAIK ISO standard C provides no way to
explicitly check the length of the varargs list, how does open() know
whether the "mode" argument was supplied or not? Or does it even need
to?


Look up.

DS
Nov 14 '05 #16
On Mon, 14 Jun 2004, Joona I Palaste wrote:
All righty, thanks. I note that this behaviour is dependent on the
POSIX standard and the ISO C standard alone does not suffice to
guarantee it.


Right; that's because ISO C has no concept of file modes (they're
a UNIX/POSIX type of thing in this case), and nor can it. Being
platform agnostic, the type of the 3rd argument for a POSIX platform
might be wildly different to that on another.

--
Rich Teer, SCNA, SCSA

President,
Rite Online Inc.

Voice: +1 (250) 979-1638
URL: http://www.rite-online.net
Nov 14 '05 #17
Joona I Palaste <pa*****@cc.helsinki.fi> wrote:
Rich Teer <ri*******@rite-group.com> scribbled the following
on comp.lang.c:
On Mon, 14 Jun 2004, Joona I Palaste wrote:
One further question: Since AFAIK ISO standard C provides no way to
explicitly check the length of the varargs list, how does open() know
whether the "mode" argument was supplied or not? Or does it even need
to?

It doesn't need to know. The writers of the function quite
reasonably assume that if O_CREAT was specified, then the 3rd
argument was also passed. If it wasn't passed, whatever junk
is on the stack at that location will be used instead.


All righty, thanks. I note that this behaviour is dependent on the
POSIX standard and the ISO C standard alone does not suffice to
guarantee it.


Yes it does. This is analogous to printf() , the difference being
that a flag bit is used instead of a character sequence starting with %
Presumably the implementation of open() (if written in ISO C and not
assembly, of course), won't attempt to extract a parameter if that
flag was not specified.
Nov 14 '05 #18
Old Wolf <ol*****@inspire.net.nz> scribbled the following
on comp.lang.c:
Joona I Palaste <pa*****@cc.helsinki.fi> wrote:
Rich Teer <ri*******@rite-group.com> scribbled the following
on comp.lang.c:
> On Mon, 14 Jun 2004, Joona I Palaste wrote:
>> One further question: Since AFAIK ISO standard C provides no way to
>> explicitly check the length of the varargs list, how does open() know
>> whether the "mode" argument was supplied or not? Or does it even need
>> to?
> It doesn't need to know. The writers of the function quite
> reasonably assume that if O_CREAT was specified, then the 3rd
> argument was also passed. If it wasn't passed, whatever junk
> is on the stack at that location will be used instead.


All righty, thanks. I note that this behaviour is dependent on the
POSIX standard and the ISO C standard alone does not suffice to
guarantee it.

Yes it does. This is analogous to printf() , the difference being
that a flag bit is used instead of a character sequence starting with %
Presumably the implementation of open() (if written in ISO C and not
assembly, of course), won't attempt to extract a parameter if that
flag was not specified.


What I meant was that the ISO C standard does not specify that open()
will only look at the third parameter if the second one's value was
O_CREAT. In fact the ISO C standard does not specify anything that
open() will do. But the POSIX standard specifies that it will act as
described here.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"B-but Angus! You're a dragon!"
- Mickey Mouse
Nov 14 '05 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: WittyGuy | last post by:
Hi, What is the major difference between function overloading and function templates? Thanks! http://www.gotw.ca/resources/clcm.htm for info about ]
17
by: Nathan Given | last post by:
Hello All, I am trying to debug a broken query. The query uses Left$(,4) instead of Left(,4). What is the difference between the Left() and Left$() functions in Microsoft Access? Thanks!...
15
by: Mohanasundaram | last post by:
Hi All, What is the difference between malloc and calloc other than the point that calloc will initialize the memory to all zeros? This was an interview question for me. All the books and...
5
by: Chris | last post by:
Hi, I don't get the difference between a struct and a class ! ok, I know that a struct is a value type, the other a reference type, I understand the technical differences between both, but...
3
by: Jarod_24 | last post by:
Dim p As Diagnostics.Process Debug.WriteLine(p.Id) Debug.WriteLine(p.Handle) What is the difference between a process's ID and Handle I see that they are different, and i know that the...
15
by: Youssef Mesri | last post by:
What is the difference between these two situations: 1- hold a namespace which contains justs some functions: namespace MyNamespace { void foo1(); void foo2(); void foo3(); void foo4();
5
by: StephQ | last post by:
This is from a thread that I posted on another forum some days ago. I didn't get any response, so I'm proposing it in this ng in hope of better luck :) The standard explanation is that pointer...
5
by: _mario.lat | last post by:
hallo, I'd like to understand the difference between socktype ad protocol: in getaddrinfo or in cration of socket we have two arguments: socketype and protocol: ai_socktype: can have...
11
by: sunnyalways4u2000 | last post by:
hello sir, Sir will please tell me the exact difference between C and advanced C...what are the extra features or funcions...etc added in this advanced one.
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.