473,657 Members | 2,661 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

diff between sprintf() and fprintf()

i have just started studying C.I know C++ before this.i havent reallly
understand the concept of sprintf().could any one plz tell me what is
the difference b/w sprintf() and fprintf() through an example

May 16 '06 #1
9 1746
"mknarang.n sit" <mk***********@ gmail.com> writes:
i have just started studying C.I know C++ before this.i havent reallly
understand the concept of sprintf().could any one plz tell me what is
the difference b/w sprintf() and fprintf() through an example


sprintf() puts its output in a string.
fprintf() writes its output to a stream (a file or device).
--
"If I've told you once, I've told you LLONG_MAX times not to
exaggerate."
--Jack Klein
May 16 '06 #2
mknarang.nsit said:
i have just started studying C.I know C++ before this.i havent reallly
understand the concept of sprintf().could any one plz tell me what is
the difference b/w sprintf() and fprintf() through an example


In your C book, look at the type of the first parameter to sprintf, and the
type of the first parameter to fprintf. In each case, the parameter
determines the place where the output of the function will be written. That
they are of different types for the two functions, then, is significant.

--
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)
May 16 '06 #3
mknarang.nsit wrote:
i have just started studying C.I know C++ before this.i havent reallly
understand the concept of sprintf().could any one plz tell me what is
the difference b/w sprintf() and fprintf() through an example


1) Sentences start with capital letters, like this one.
2) Space comes after a period and before the beginning of the next
sentence, one or two is fine.
3) In the english language we always capitalize the word "I".
4) Don't use abbreviations like "plz" in a technical group like this
one if you want to be taken seriously.

Also, since you are posting from Google Groups, please be sure to read
<http://cfaj.freeshell. org/google/> before posting a followup.

Now to your question: sprintf writes to a character buffer, fprintf
writes to a stream. See your local documentation or a good C book for
the details.

Robert Gamble

May 16 '06 #4

"Robert Gamble" <rg*******@gmai l.com> wrote in message
news:11******** **************@ u72g2000cwu.goo glegroups.com.. .
mknarang.nsit wrote:
i have just started studying C.I know C++ before this.i havent reallly
understand the concept of sprintf().could any one plz tell me what is
the difference b/w sprintf() and fprintf() through an example
1) Sentences start with capital letters, like this one.
2) Space comes after a period and before the beginning of the next
sentence, one or two is fine.
3) In the english language we always capitalize the word "I".


And in the English language, we capitalize proper nouns like "English",
unless you mean to imply spin on a ball...
4) Don't use abbreviations like "plz" in a technical group like this
one if you want to be taken seriously.

Also, since you are posting from Google Groups, please be sure to read
<http://cfaj.freeshell. org/google/> before posting a followup.

Now to your question: sprintf writes to a character buffer, fprintf
writes to a stream. See your local documentation or a good C book for
the details.

Robert Gamble


--
Fred
May 16 '06 #5

"Fred Kleinschmidt" <fr************ ******@boeing.c om> wrote in message
news:Iz******** @news.boeing.co m...

"Robert Gamble" <rg*******@gmai l.com> wrote in message
news:11******** **************@ u72g2000cwu.goo glegroups.com.. .
mknarang.nsit wrote:
i have just started studying C.I know C++ before this.i havent reallly
understand the concept of sprintf().could any one plz tell me what is
the difference b/w sprintf() and fprintf() through an example


1) Sentences start with capital letters, like this one.
2) Space comes after a period and before the beginning of the next
sentence, one or two is fine.
Actually, two spaces are required after a period. One is insufficient.
3) In the english language we always capitalize the word "I".


And in the English language, we capitalize proper nouns like "English",
unless you mean to imply spin on a ball...
4) Don't use abbreviations like "plz" in a technical group like this
one if you want to be taken seriously.

Also, since you are posting from Google Groups, please be sure to read
<http://cfaj.freeshell. org/google/> before posting a followup.

Now to your question: sprintf writes to a character buffer, fprintf
writes to a stream. See your local documentation or a good C book for
the details.

Robert Gamble


--
Fred


The Grue
May 17 '06 #6

"The Grue - James T. Sprinkle" <th******@hotma il.com> wrote in message
news:dM******** *********@news0 1.roc.ny...

"Fred Kleinschmidt" <fr************ ******@boeing.c om> wrote in message
news:Iz******** @news.boeing.co m...

"Robert Gamble" <rg*******@gmai l.com> wrote in message
news:11******** **************@ u72g2000cwu.goo glegroups.com.. .
mknarang.nsit wrote:
> i have just started studying C.I know C++ before this.i havent reallly> understand the concept of sprintf().could any one plz tell me what is
> the difference b/w sprintf() and fprintf() through an example

1) Sentences start with capital letters, like this one.
2) Space comes after a period and before the beginning of the next
sentence, one or two is fine.
Actually, two spaces are required after a period. One is insufficient.
3) In the english language we always capitalize the word "I".


And in the English language, we capitalize proper nouns like "English",
unless you mean to imply spin on a ball...
4) Don't use abbreviations like "plz" in a technical group like this
one if you want to be taken seriously.

Also, since you are posting from Google Groups, please be sure to read
<http://cfaj.freeshell. org/google/> before posting a followup.

Now to your question: sprintf writes to a character buffer, fprintf
writes to a stream. See your local documentation or a good C book for
the details.

Robert Gamble


--
Fred


The Grue


Two is what you learned in typing, one is usually sufficient and zero is ok
if
you parser works well.

barry
May 17 '06 #7
Barry wrote:

"The Grue - James T. Sprinkle" <th******@hotma il.com> wrote in message
news:dM******** *********@news0 1.roc.ny...

"Fred Kleinschmidt" <fr************ ******@boeing.c om> wrote in message
news:Iz******** @news.boeing.co m...

"Robert Gamble" <rg*******@gmai l.com> wrote in message
news:11******** **************@ u72g2000cwu.goo glegroups.com.. .
> mknarang.nsit wrote:
>> i have just started studying C.I know C++ before this.i havent reallly >> understand the concept of sprintf().could any one plz tell me what is
>> the difference b/w sprintf() and fprintf() through an example
>
> 1) Sentences start with capital letters, like this one.
> 2) Space comes after a period and before the beginning of the next
> sentence, one or two is fine.
Actually, two spaces are required after a period. One is insufficient.
> 3) In the english language we always capitalize the word "I".

And in the English language, we capitalize proper nouns like "English",
unless you mean to imply spin on a ball...

> 4) Don't use abbreviations like "plz" in a technical group like this
> one if you want to be taken seriously.
>
> Also, since you are posting from Google Groups, please be sure to read
> <http://cfaj.freeshell. org/google/> before posting a followup.
>
> Now to your question: sprintf writes to a character buffer, fprintf
> writes to a stream. See your local documentation or a good C book for
> the details.
>
> Robert Gamble
>

--
Fred


The Grue


Two is what you learned in typing, one is usually sufficient and zero is ok
if
you parser works well.


I have left this monstrosity as it appears on my system. Your
comment is nearly meaningless. It is almost as bad to fail to snip
irelevant material as to fail to quote. Below is the way it SHOULD
have looked, IMO:

Barry wrote: "The Grue - James T. Sprinkle" <th******@hotma il.com> wrote in message
"Fred Kleinschmidt" <fr************ ******@boeing.c om> wrote in message
"Robert Gamble" <rg*******@gmai l.com> wrote in message

1) Sentences start with capital letters, like this one.
2) Space comes after a period and before the beginning of the
next sentence, one or two is fine.
Actually, two spaces are required after a period. One is
insufficient.

.... snip ...
Two is what you learned in typing, one is usually sufficient and
zero is ok if you parser works well.


I hope you see the difference. Just some judicious deletia,
followed by minor reformatting. This tends to encourage others to
read it, which I presume is your (and my) objective.

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell. org/google/>
Also see <http://www.safalra.com/special/googlegroupsrep ly/>
May 17 '06 #8
On 2006-05-17, The Grue - James T. Sprinkle <th******@hotma il.com> wrote:

Actually, two spaces are required after a period. One is
insufficient.


The typographical (not grammatical) need for that faded with the
typewriter.
May 17 '06 #9
"The Grue - James T. Sprinkle" <th******@hotma il.com> wrote:
"Robert Gamble" <rg*******@gmai l.com> wrote in message
news:11******** **************@ u72g2000cwu.goo glegroups.com.. .
1) Sentences start with capital letters, like this one.
2) Space comes after a period and before the beginning of the next
sentence, one or two is fine.


Actually, two spaces are required after a period. One is insufficient.


This has never been true outside the USA, and ever there, it was only
"necessary" (the real need is not apparent from a normal layout POV) on
typewriters. Proper typography is, and always has been, a single space.

Richard
May 22 '06 #10

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

Similar topics

1
5119
by: CJ | last post by:
Ok, I've got a string class that stores the data in a dynamically allocated "char* m_pData" variable. I'd like to write a member function similiar to "sprintf" for this class. When implementing this member function, I'd like to just call "sprintf" under the covers. The problem is, that I dont' know how large the resulting string will be and thus I don't know how much space I'll need to allocate for my m_pData pointer. Is there any...
10
9936
by: ios | last post by:
Hi Can someone tell me what is different between below case? strcpy(eventname, "MDCX_RSP"); and sprintf(eventname, "MDCX_RSP"); Thanks, Leon
3
42278
by: huey_jiang | last post by:
Hi All, I am trying to figure out a right syntax to convert an integer array into hex array. sprintf worked for me on doing single integer: int i, Iarray, n=15; char buf; sprintf(buf, "0x%02x", n); The above code worked. Howeve, what I am trying to do is to convert an
9
1928
by: Matt Garman | last post by:
I'm trying to develop (for my own personal use) a general "messaging facility" in C. The idea is that the facility will be used for both debugging/logging and user interfacing. I'd like it to be fairly portable, but as robust and reliable as possible. My intent is to develop an API for such general messaging. I'll implement the parts that write to stdout, stderr and files. Later, I'll add support for writing to (for example) syslog,...
1
3519
by: jimjim | last post by:
Hello, I was wondering about the implications of giving as an argument to sprintf a different data type from the one specified in the format argument. This type of question along with some others are asked below: 1. #include <stdio.h> int main(){ char buffer;
9
6508
by: Ching-Lung | last post by:
Hi all, I try to create a tool to check the delta (diff) of 2 binaries and create the delta binary. I use binary formatter (serialization) to create the delta binary. It works fine but the delta binary is pretty huge in size. I have 1 byte file and 2 bytes file, the delta should be 1 byte but somehow it turns out to be 249 bytes using binary formatter. I guess serialization has some other things added to the delta file.
4
4950
by: Andreas Kasparek | last post by:
Hola! I'm preparing my master thesis about a XML Merge Tool implementation and was wondering if there is any open standard for XML diff regarding topics like: - is a diff result computed on the ordered or unordered xml node tree of the compared documents? - what identifiers/criteria should be used by default to match elements of the same type in different documents? - should a diff tool consider move operations or only insert/delete
66
3104
by: gyan | last post by:
Hi All, I am using sprintf and getting starnge output in following case char temp_rn; memset(temp_rn,'\0',12); sprintf(temp_rn,"0%s",temp_rn); the final value in temp_rn is 00 how it is behaving like this, when source string and output string is
173
13884
by: Ron Ford | last post by:
I'm looking for a freeware c99 compiler for windows. I had intended to use MS's Visual C++ Express and use its C capability. In the past with my MS products, I've simply needed to make .c the filetype to invoke the C compiler. Here's a link http://www.microsoft.com/express/download/#webInstall The download is 2.6 megs, which is near a reasonable size for a compiler, but then setup.exe wants to download 87 megs of dot net framework...
0
8319
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8837
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8512
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7347
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6175
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2739
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.