473,790 Members | 3,200 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sscanf return value with "%n" directive

The return value of sscanf should be "the number of input items
assigned" (unless an input failure occurs before any conversion). Are
items assigned due to a "%n" directive included in the returned count?

Thanks.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Nov 13 '05 #1
4 6492
Kevin Goodsell wrote:
The return value of sscanf should be "the number of input items
assigned" (unless an input failure occurs before any conversion). Are
items assigned due to a "%n" directive included in the returned count?

Thanks.


Follow-up question: Is the answer to my first question the same for both
C89 and C99? If not, what's the difference?

Thanks again.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Nov 13 '05 #2
Kevin Goodsell wrote:

The return value of sscanf should be "the number of input items
assigned" (unless an input failure occurs before any conversion). Are
items assigned due to a "%n" directive included in the returned count?
No (Source: K&R, page 246).
Follow-up question: Is the answer to my first question the same for both
C89 and C99?


Yes (Source: C99, section 7.19.6.2.).

--
Russell Hanneken
rg********@pobo x.com
Remove the 'g' from my address to send me mail.

Nov 13 '05 #3
Kevin Goodsell wrote:

The return value of sscanf should be "the number of input items
assigned" (unless an input failure occurs before any conversion).
Are items assigned due to a "%n" directive included in the
returned count?


No. From N869, 7.19.6.2:

n No input is consumed. The corresponding argument
shall be a pointer to signed integer into which is
to be written the number of characters read from the
input stream so far by this call to the fscanf
function. Execution of a %n directive does not
increment the assignment count returned at the
completion of execution of the fscanf function. No
argument is converted, but one is consumed. If the
conversion specification includes an assignment-
suppressing character or a field width, the behavior
is undefined.

and the specification for C89 is the same. This is also shown by
the following program (ggets mallocs space for and inputs a
complete line):

#include <stdio.h>
#include <stdlib.h>
#include "ggets.h"

int countints(void)
{
char *ln;
int num;
int count;
int ix, delta;

count = 0; ix = 0;
if (0 == ggets(&ln)) {
while (1 == sscanf(&ln[ix], "%d%n", &num, &delta)) {
printf("[%d]%d ", ix, num);
ix += delta;
count++;
}
printf(": %d\n", count);
free(ln);
}
return count;
} /* countints */

/* ------------------ */

int main(void)
{
while (countints()) continue;
return 0;
} /* main */

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!

Nov 13 '05 #4
Russell Hanneken wrote:
Kevin Goodsell wrote:
The return value of sscanf should be "the number of input items
assigned" (unless an input failure occurs before any conversion). Are
items assigned due to a "%n" directive included in the returned count?

No (Source: K&R, page 246).

Follow-up question: Is the answer to my first question the same for both
C89 and C99?

Yes (Source: C99, section 7.19.6.2.).


Both of those sources were right in front of me and I managed to miss
the answer in both. For some reason I didn't think it would be in the
description of %n, so I barely glanced at that. :-/

Thanks Russell & Chuck.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Nov 13 '05 #5

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

Similar topics

5
2364
by: lvcha.gouqizi | last post by:
I embed an applet in my php script which has a parameter providing an input file for the jar. Does this file has size limit? The code is as follows: <APPLET ARCHIVE="myapplet.jar" WIDTH=372 HEIGHT=360 VSPACE=0 HSPACE=0 ALIGN=middle> <?php echo "<PARAM NAME=\"data\" VALUE=\"myfile.\">";?> when "myfile" is beyond 15M, my applet cannot load sucessfully, but
32
8878
by: Mike Machuidel | last post by:
Hi, I'm a game developer programming mostly in C and ASM for about 7 years. Today at work a colleague (a C++ programmer) yelled at me I'm a bad C programmer because I use "return(0);" instead of "return 0;". He explained that "return" is not a function but a stament, like I didn't know already. The other colleagues also argreed with him :(. Can someone please explain what's so wrong about using "return" with
10
2621
by: LaEisem | last post by:
On-the-job, I have "inherited" a lot of old C language software. A question or two about when "casting" of null pointer constants is needed has occurred during behind-the-scenes cleanup of some of that software. That subject seems not to be addressed, at least not directly, in the C FAQ where FAQ 5.2 seems most relevant. References: * C FAQ 5.2 Null pointers (Including conditions where "casting" of null pointer...
15
6733
by: Greenhorn | last post by:
Hi, when a function doesn't specify a return type ,value what value is returned. In the below programme, the function sample()is returning the value passed to 'k'. sample(int); main() { int i = 0,j; j = sample(0);
5
6759
by: n_o_s_p_a__m | last post by:
Can't compile. Does this mean that all functions that throw exceptions must be of return type void? examples: // won't compile: "not all code paths return a value" public override int Run() { throw new Exception("exception thrown"); }
12
4133
by: Jose Fernandez | last post by:
Hello. I'm building a web service and I get this error. NEWS.News.CoverNews(string)': not all code paths return a value This is the WebMethod public SqlDataReader CoverNews(string Sport) {
5
8091
by: Dmitriy Lapshin [C# / .NET MVP] | last post by:
Hi all, I think the VB .NET compiler should at least issue a warning when a function does not return value. C# and C++ compilers treat this situation as an error and I believe this is the right thing to do. And I wonder why VB .NET keeps silence and makes such function return some default value instead. Isn't it error-prone? -- Dmitriy Lapshin
32
2218
by: Axel Bock | last post by:
Hi all, I am trying to get my head around what happens if I return a class object from a function. It seems C++ (MinGW) does not invoke the copy constructor if I do something like this: SomeObj foo() { SomeObj X;
4
1320
by: yaru22 | last post by:
In one of the examples in the book I'm reading, it says: def __init__(self): ... ... ... return It has nothing after "return". I expected it to have some number like 0 or 1.
0
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10419
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
10201
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
10147
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
9023
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
7531
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
6770
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2910
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.