473,396 Members | 2,018 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,396 software developers and data experts.

sscanf feature in C++?

Do we have sscanf feature in C++? I guess since C++ is superset of C.
So the following are valid C++ code. Is that true?

char* buf = "10:25:33";
sscanf(buf, "%d:%d:%d", &h, &m, &s);

Please advise. thanks!!
Nov 14 '05 #1
9 3437
In article <ba**************************@posting.google.com >,
Matt <jr********@hotmail.com> wrote:
Do we have sscanf feature in C++? I guess since C++ is superset of C.
So the following are valid C++ code. Is that true?

char* buf = "10:25:33";
sscanf(buf, "%d:%d:%d", &h, &m, &s);

Please advise. thanks!!
Since this is comp.lang.c, the best answer we can give you is "This is
perfectly valid C".

If you go ask this in comp.lang.c++, they'll tell you that it's also
perfectly valid C++ (assuming you have an appropriate using directive in
scope or use the C-style header names instead of the C++-style header
names), and possibly also mention std::strstream as a more C++-ish
alternative.
dave

--
Dave Vandervies dj******@csclub.uwaterloo.caWrong.

May I be excused for showing incomplete/incorrect knowledge of C++ knowledge
in a C newsgroup? --Michael Rubenstein and Ian Woods in comp.lang.c
Nov 14 '05 #2
Matt wrote:
Do we have sscanf feature in C++?
"We", in comp.lang.c, don't, because we program in C. The folks in
comp.lang.c++ would tell you that they have sscanf, but many are likely
to tell you to use some C++ "feature" instead.
I guess since C++ is superset of C.
Your premise is wrong. C++ is not a superset of C. Whoever told you
that should be ignored: he is a fool.
So the following are valid C++ code.
We don't know: comp.lang.c doesn't do C++. But.. Is that true?

char* buf = "10:25:33";
sscanf(buf, "%d:%d:%d", &h, &m, &s);


This legal C program

#include <stdio.h>

int main(void)
{
char *buf = "10:25:33";
int h, m, s;
sscanf(buf, "%d:%d:%d", &h, &m, &s);
printf("%d hours + %d minutes + %d seconds\n", h, m, s);
return 0;
}

produces this output
10 hours + 25 minutes + 33 seconds

and this probably legal (but check comp.lang.c++ where they do C++) C++
program

#include <cstdio>

int main()
{
char *buf = "10:25:33";
int h, m, s;
sscanf(buf, "%d:%d:%d", &h, &m, &s);
printf("%d hours + %d minutes + %d seconds\n", h, m, s);
}

produces this output
10 hours + 25 minutes + 33 seconds

Nov 14 '05 #3
Matt wrote:
Do we have sscanf feature in C++?
This is comp.lang.c. You want comp.lang.c++.
I guess since C++ is superset of C.
This is a false statement.
So the following are valid C++ code. Is that true?

char* buf = "10:25:33";
sscanf(buf, "%d:%d:%d", &h, &m, &s);


<OT>
The C standard library, for the most part, is included in C++.
</OT>
Brian
Nov 14 '05 #4
Martin Ambuhl <ma*****@earthlink.net> writes:
Matt wrote:

[...]
I guess since C++ is superset of C.


Your premise is wrong. C++ is not a superset of C. Whoever told you
that should be ignored: he is a fool.


Yes, but C++ is very nearly a superset of C (specifically C90). In
particular, it includes the C90 standard library, including the sscanf
function.

You can't expect an arbitrary C program to be a valid C++ program with
the same semantics, but the intersection of the two languages is quite
large, and not much smaller than C itself.

--
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.
Nov 14 '05 #5
"Default User" <fi********@boeing.com.invalid> wrote in message
news:I5*******@news.boeing.com...
<OT>
The C standard library, for the most part, is included in C++.
</OT>


Which parts are left out?

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Nov 14 '05 #6
P.J. Plauger wrote:
"Default User" <fi********@boeing.com.invalid> wrote in message
news:I5*******@news.boeing.com...
<OT>
The C standard library, for the most part, is included in C++.
</OT>


Which parts are left out?

What I meant was, "for the most part without alteration". I'm not 100%
sure there aren't some slight syntax/semantic differences due to the
differences between the two languages.

I was merely hedging my bets slightly. You'd know, of course.


Brian
Nov 14 '05 #7
"P.J. Plauger" wrote:
"Default User" <fi********@boeing.com.invalid> wrote in message
<OT>
The C standard library, for the most part, is included in C++.
</OT>


Which parts are left out?


A shining example of "insert knife slowly and gently, then twist".
:-)

--
"I support the Red Sox and any team that beats the Yankees"
"Any baby snookums can be a Yankee fan, it takes real moral
fiber to be a Red Sox fan"
"I listened to Toronto come back from 3:0 in '42, I plan to
watch Boston come back from 3:0 in 04"
Nov 14 '05 #8
In <1098190311.jKmdba3Q56d40hxC28JwdQ@teranews> "P.J. Plauger" <pj*@dinkumware.com> writes:
"Default User" <fi********@boeing.com.invalid> wrote in message
news:I5*******@news.boeing.com...
<OT>
The C standard library, for the most part, is included in C++.
</OT>


Which parts are left out?


Most of the bits that are new in C99 are not in the standard C++ library.

4 Except as noted in clauses 18 through 27, the contents of each header
cname shall be the same as that of the corresponding header name.h,
as specified in ISO/IEC 9899:1990 Programming Languages C (Clause
^^^^
7), or ISO/IEC:1990 Programming LanguagesC AMENDMENT 1: C Integrity,
(Clause 7), as appropriate, as if by inclusion. In the C++ Standard
Library, however, the declarations and definitions (except for names
which are defined as macros in C) are within namespace scope (3.3.5)
of the namespace std.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Currently looking for a job in the European Union
Nov 14 '05 #9
CBFalconer wrote:
"P.J. Plauger" wrote:
"Default User" <fi********@boeing.com.invalid> wrote in message
<OT>
The C standard library, for the most part, is included in C++.
</OT>


Which parts are left out?


A shining example of "insert knife slowly and gently, then twist".


I already replied to that. It was a hedge for a possible gap in my
knowledge of C++. Reasonable under the circumstances and locale, I'd
say.

Brian
Nov 14 '05 #10

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

Similar topics

14
by: Matt | last post by:
Do we have sscanf feature in C++? I guess since C++ is superset of C. So the following are valid C++ code. Is that true? char* buf = "10:25:33"; sscanf(buf, "%d:%d:%d", &h, &m, &s); Please...
4
by: smshahriar | last post by:
Hi, I want to scan from the following string all the hex numbers and populate an array of integers: 0x27 0x00 0x30 0x00 0x33 0x00 0x36 0x00
10
by: baumann | last post by:
hi, 1) first test program code #include <stdio.h> int main(void) { char * file = "aaa 23 32 m 2.23 ammasd"; int i2,i3;
4
by: baumann | last post by:
hi all there has 2 program 1) the first test program code #include <stdio.h> int main(void) {
5
by: jchludzinski | last post by:
I'm using strtok() to parse thru a line and read different numbers: float value; char *token; token = strtok( line, " " ); .... sscanf( token, "%f", &value ); These results are less...
22
by: Superfox il Volpone | last post by:
Hello I have some problem with sscanf, I tryed this code but it doesn't works : char* stringa = "18/2005" char mese; char anno; int i_letture; i_letture = sscanf(stringa, "%2s/%4s",...
8
by: Artemio | last post by:
Dear folks, I need some help with using the sscanf() function. I need to parse a string which has several parameters given in a "A=... B=... C=..." way, and each has a different type (one is a...
20
by: AMP | last post by:
Hello, Anybody know if anything exists like sscanf in c. I found a few things OL but most were pretty old. Maybe something has come along since 2004? Thanks Mike
5
by: Alex Mathieu | last post by:
Hi, using sscanf, I'm trying to retrieve something, but nothing seems to work. Here's the pattern: SS%*sþ0þ%6s Heres the data: SS000000395000000000DC-þ0þ799829þ1174503725þ Actually, I...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.