Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Difference between various functions

Reply
Thread Tools

Difference between various functions

 
 
SDZ
Guest
Posts: n/a
 
      06-14-2004
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
 
Reply With Quote
 
 
 
 
Joona I Palaste
Guest
Posts: n/a
 
      06-14-2004
SDZ <(E-Mail Removed)> 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 ((E-Mail Removed)) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"It was, er, quite bookish."
- Horace Boothroyd
 
Reply With Quote
 
 
 
 
Paulo PEREIRA
Guest
Posts: n/a
 
      06-14-2004
On 2004-06-14, Joona I Palaste <(E-Mail Removed)> wrote:
> SDZ <(E-Mail Removed)> 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]
 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      06-14-2004
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
 
Reply With Quote
 
=?iso-8859-1?q?Nils_O=2E_Sel=E5sdal?=
Guest
Posts: n/a
 
      06-14-2004
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

 
Reply With Quote
 
Joona I Palaste
Guest
Posts: n/a
 
      06-14-2004
Nils O. Selåsdal <(E-Mail Removed)> 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 ((E-Mail Removed)) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Normal is what everyone else is, and you're not."
- Dr. Tolian Soran
 
Reply With Quote
 
Goran Larsson
Guest
Posts: n/a
 
      06-14-2004
In article <cal2es$cr9$(E-Mail Removed)>,
Joona I Palaste <(E-Mail Removed)> wrote:

> Nils O. Selåsdal <(E-Mail Removed)> 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/
 
Reply With Quote
 
Dragan Cvetkovic
Guest
Posts: n/a
 
      06-14-2004
Joona I Palaste <(E-Mail Removed)> writes:

> Nils O. Selåsdal <(E-Mail Removed)> 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 !!!
 
Reply With Quote
 
Ben Pfaff
Guest
Posts: n/a
 
      06-14-2004
Joona I Palaste <(E-Mail Removed)> writes:

> Nils O. Selåsdal <(E-Mail Removed)> 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
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      06-14-2004
Joona I Palaste wrote:
> Nils O. Selåsdal <(E-Mail Removed)> 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>

--
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Direct support for various Statistical functions Michael Angelo Ravera C Programming 1 12-18-2009 07:32 AM
Difference between bin and obj directories and difference between project references and dll references jakk ASP .Net 4 03-22-2005 09:23 PM
Functions that accept various type? QQ C Programming 8 12-14-2004 11:49 PM
please help me in distinguish redefining functions, overloading functions and overriding functions. Xiangliang Meng C++ 1 06-21-2004 03:11 AM
Accessing files from various functions Lorenzo Mugnai C Programming 1 08-12-2003 03:45 PM



Advertisments