473,387 Members | 1,517 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,387 software developers and data experts.

fscanf and NULL

I have failed to find an authoritive answer on the following:

fscanf(NULL, ..);

The rest of the function arguments have been omitted.

I'm only curious as to what behavior is given when
the first argument is NULL?

I went through J.2 of the standard but it isn't listed as
undefined behavior nor implementation defined.

Anyone know where it says what type of behavior this invokes?

--
nethlek
Nov 14 '05 #1
3 3452
Mantorok Redgormor wrote:
I have failed to find an authoritative answer on the following:

fscanf(NULL, ..);

The rest of the function arguments have been omitted.

I'm only curious as to what behavior is given when
the first argument is NULL?

I went through J.2 of the standard but it isn't listed as
undefined behavior nor implementation defined.

Anyone know where it says what type of behavior this invokes?


It is used to reformat your hard disk drive. :-)

Nov 14 '05 #2
On 22 Jan 2004 16:45:31 -0800, ne*****@tokyo.com (Mantorok Redgormor)
wrote in comp.lang.c:
I have failed to find an authoritive answer on the following:

fscanf(NULL, ..);

The rest of the function arguments have been omitted.

I'm only curious as to what behavior is given when
the first argument is NULL?

I went through J.2 of the standard but it isn't listed as
undefined behavior nor implementation defined.

Anyone know where it says what type of behavior this invokes?


<quote>
7.1.4 Use of library functions
1 Each of the following statements applies unless explicitly stated
otherwise in the detailed descriptions that follow: If an argument to
a function has an invalid value (such as a value outside the domain of
the function, or a pointer outside the address space of the program,
or a null pointer, or a pointer to non-modifiable storage when the
corresponding parameter is not const-qualified) or a type (after
promotion) not expected by a function with variable number of
arguments, the behavior is undefined.
<unquote>

Since the definition of fscanf() does not specifically state that the
first argument may be a null pointer, as for example realloc() or
strtol() do, passing one results in undefined behavior.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #3
In <41**************************@posting.google.com > ne*****@tokyo.com (Mantorok Redgormor) writes:
I have failed to find an authoritive answer on the following:

fscanf(NULL, ..);

The rest of the function arguments have been omitted.

I'm only curious as to what behavior is given when
the first argument is NULL?


You don't even need the standard in order to figure out the answer:
fscanf expects a valid stream as its first argument and NULL doesn't
match this description. Undefined behaviour.

The only exception to this rule is fflush, which flushes all the streams
that can be flushed when given NULL instead of a valid stream.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #4

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

Similar topics

3
by: Benedicte | last post by:
Hi, I'm getting some problems when using fscanf to read a file. This is a piece of the program code: main () { /*** Variable declaration ***/ FILE *vpfile; /*** Data file ***/
4
by: Cal Lidderdale | last post by:
My input line is i1,i2,i3,i4,i5,i6,i7,i8^,...i596,597, ... 14101,14102...NL/CR very long line of data - I only want the first 8 items and the delimiter between 8 & 9 is a carrot "^". The line...
5
by: learner | last post by:
I have datafiles like this: 0 1941 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.02 0.00 0.00 1 0 1941 0.00 0.03 0.00 0.03 0.04 0.02 0.00 0.00 0.00 0.00 2 0 1941 0.00 0.00 0.00 0.00 0.52...
1
by: siliconwafer | last post by:
Hi All, here is one code: int main() { FILE*fp; unsigned long a; fp = fopen("my_file.txt","w+"); a = 24; fprintf(fp,"%ld",a); while(fscanf(fp,"%ld",&a) == 1) {
7
by: bhanuprakash | last post by:
I am trying to use fscanf to read my test file. In my test file i sometimes have blank lines. When I try to read using the following format. fscanf(fp,"%\n",temp_str); If there is any blank...
3
by: totoro2468 | last post by:
Hi, I'm a complete NOOB. How do I get fscanf to copy into an array? I also need to use malloc, but where do I put it in my file? _______________________________________________________ FILE...
13
by: PeterOut | last post by:
I am using MS Visual C++ 6.0 on Windows XP 5.1 (SP2). I am not sure if this is a C, C++ or MS issue but fscanf has been randomly hanging on me. I make the call hundreds, if not thousands, of...
10
by: Roman Zeilinger | last post by:
Hi I have a beginner question concerning fscanf. First I had a text file which just contained some hex numbers: 0C100012 0C100012 ....
1
momotaro
by: momotaro | last post by:
I have a small problem with the last fscanf in this function...every thing is logic in there but can't find the problem... plz help node *BuildGraph() { int range, vehicules, i, j,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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:
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
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...

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.