Talk:Scanf format string

From Wikipedia, the free encyclopedia
Jump to: navigation, search
WikiProject Computing (Rated Start-class)
WikiProject icon This article is within the scope of WikiProject Computing, a collaborative effort to improve the coverage of computers, computing, and information technology on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
Start-Class article Start  This article has been rated as Start-Class on the project's quality scale.
 ???  This article has not yet received a rating on the project's importance scale.
 
WikiProject C/C++  
WikiProject icon This article is within the scope of WikiProject C/C++, a collaborative effort to improve the coverage of C/C++ on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
 ???  This article has not yet received a rating on the quality scale.
 ???  This article has not yet received a rating on the importance scale.
 


Untitled[edit]

And the usage? Do you have to press enter after setting the value? -212.149.219.87 14:57, 15 May 2007 (UTC)

That should be answered here, as a property of unix stdin--190.31.123.176 (talk) 04:11, 31 July 2008 (UTC)

"Unlike scanf and fscanf, sscanf does not remove the read items away from the input flush. [...]" -- What's an input flush? —Preceding unsigned comment added by 98.202.233.57 (talk) 08:31, 5 March 2009 (UTC)

Acceptance of negative values by %u[edit]

The text doesn't explain why (counter-intuitively) %u accepts a negative value to an unsigned integer. "" being optional is irrelevant; if the input string doesn't contain "", you have the normal case of specifying a non-negative integer. The article on strtoul() doesn't explain either, hence my tags. -- Regregex (talk) 15:37, 15 January 2011 (UTC)

This page so does not belong in Wikipedia[edit]

— Preceding unsigned comment added by 98.108.219.226 (talkcontribs) 18:27, 25 February 2010

scanf edge-cases[edit]

Does "%%" skip leading whitespace? That is, is it equivalent to " %%" or "%*1[%]"? What is the way to match a character class equivalent to a single caret (not "^" but a potentially unlimited string of "^")? Something like "%[^]" doesn't work because the character class isn't closed. 130.101.140.16 (talk) 17:04, 19 April 2011 (UTC)

scanf unsourced claim[edit]

The unsourced claim in section security does not work under gcc4.6 : the text implies that

scanf("Please enter a value %d",&n);

would output something like this while waiting for an integer

Please enter a value 

However, the following code, compiled with gcc -Wall -Werror -ansi -pedantic

#include <stdio.h>
int main(){
    int d = 0;
    scanf("enter integer: %d", &d);
    printf("entered integer: %d\n", d);
    return 0;
}

gives

$ ./a.out
10
entered integer: 0
$ ./a.out
enter integer: 10
entered integer: 10

That is, you must enter 'enter integer ' before your actual input for it to work. Since the hypothesized behaviour does not seem to be widely implemented, i'm removing that claim (which also has nothing to do in the security section).

Je ne détiens pas la vérité universelle (talk) 22:28, 7 February 2012 (UTC)

This makes no sense[edit]

"As scanf is designated to read only from standard input, many programming languages with interfaces, such as PHP, have derivatives such as sscanf and fscanf but not scanf itself."

This has nothing to do with interfaces being present in the language or not. — Preceding unsigned comment added by 24.30.53.212 (talk) 17:10, 20 February 2012 (UTC)

Alternatives[edit]

A section mentioning functions such as atof(3), atoi(3), atol(3), strtod(3), strtoul(3) might be a good addition. — Preceding unsigned comment added by 75.154.106.91 (talk) 15:55, 13 January 2013 (UTC)