Questions tagged [formatted-input]

Anything related to the reading of input that shall be compliant with a predefined format

Definition

Formatted input is anything related to the reading of input that shall be compliant with a predefined format.

Example:

  • verifying/enforcing the format of an imput field
  • recognizing formatting for interpretation of read data.
  • use of dedicated library function (like scanf() in C)

Related topics

Formatted input is related to several other subjects:

  • when format has to comply with file formatting standards
  • when reading formetted-input provided by a user
  • when it's only about enforcing compliance of input
  • when it's about more very complex formatting patterns and rules
  • is a technique that often contributes to implement formatted input.
  • when the format is used to splitting input in smaler tokens
57 questions
29
votes
5 answers

C# equivalent of C sscanf

Possible Duplicate: Is there an equivalent to 'sscanf()' in .NET? sscanf in C is a nice way to read well formatted input from a string. How to achieve this C#. For example, int a,b; char *str= "10 12"; sscanf(str,"%d %d",&a,&b); The above code…
Shamim Hafiz - MSFT
  • 21,454
  • 43
  • 116
  • 176
21
votes
7 answers

Does anyone actually use stream extraction operators?

I've written tons of operator<<(std::ostream &, const T &) functions -- they're incredibly useful. I've never written an operator>>(std::istream &, T &) function in real code or even used the extraction operators for built-in types (OK, maybe for…
Dan
  • 5,929
  • 6
  • 42
  • 52
20
votes
5 answers

C++ formatted input: how to 'skip' tokens?

Suppose I have an input file in this format: VAL1 VAL2 VAL3 VAL1 VAL2 VAL3 I'm writing a program that would be interested only in VAL1 and VAL3. In C, if i wanted to 'skip' the second value, I'd do as follows: char VAL1[LENGTH]; char…
Rafael Almeida
  • 10,352
  • 6
  • 45
  • 60
13
votes
5 answers

Reading formatted data with C++'s stream operator >> when data has spaces

I have data in the following format: 4:How do you do? 10:Happy birthday 1:Purple monkey dishwasher 200:The Ancestral Territorial Imperatives of the Trumpeter Swan The number can be anywhere from 1 to 999, and the string is at most 255 characters…
dreamlax
  • 93,976
  • 29
  • 161
  • 209
8
votes
3 answers

Use scanf with Regular Expressions

I've been trying to use regular expressions on scanf, in order to read a string of maximum n characters and discard anything else until the New Line Character. Any spaces should be treated as regular characters, thus included in the string to be…
someone
  • 361
  • 2
  • 3
  • 13
5
votes
4 answers

How to extract mixed format using istringstream

Why does my program not output: 10 1.546 ,Apple 1 instead of 10 1 here's my program: #include #include #include using namespace std; int main () { string str = "10,1.546,Apple 1"; …
Sunil Kundal
  • 143
  • 1
  • 2
  • 8
4
votes
3 answers

problems with scanf("%d\n",&i)

For this code: int i; scanf("%d\n",&i); I am not able to stop my program until I input two numbers. I think it is very strange ,I know when the input is suitable,the scanf will return 1. When I input "12a 'Enter'","12 'Enter'2" and so on ,it is…
Sphinx
  • 315
  • 1
  • 3
  • 6
4
votes
2 answers

How do I define a function that accepts a formatted input string in C?

I built a custom logging function that takes in a "log level" and string. A user would specify the log level associated with the message (i.e. error, warning, trace, etc.). The logging function would only print the message to the console depending…
Izzo
  • 4,461
  • 13
  • 45
  • 82
4
votes
1 answer

Formatted input array int

I need to be able to enter array of ints and hold it in a set inside a struct, however for some reason it won't read the numbers into the array: #include #include #include #define MAX 100 typedef struct set { …
Milo
  • 131
  • 10
3
votes
5 answers

Stop reading at format mismatch

I have a file such as: 1.0000000e+01 8.0123000e+01 1.0000000e+01 1.0000000e+01 1.0000000e+01 -1.0000000e+01 1.0000000e+01 1.0001110e+01 1.0000000e+01 1.0000000e+01 1.0000000e+01 1.0000000e+01 -5.0000000e+01 1.0000000e+01 …
Biga
  • 317
  • 1
  • 3
  • 11
3
votes
1 answer

formatted input from string in Pascal

In Pascal (Delphi, Lazarus), there is the Format() function for creating a formatted string from a list of variables. It works in a similar way to sprintf() function in C/C++. On the other hand, I am not aware of any function which would set…
Plzak
  • 43
  • 3
3
votes
3 answers

What's the C++ version of scanf?

For example... char* foo; scanf("%[^\n\r]", foo); How can I do this in C++, without including C libraries?
3
votes
2 answers

Parse a formatted string into arrays of arrays

+2-1+18*+7-21+3*-4-5+6x29 The above string is an example of the kind of string I'm trying to split into either a key => value array or something similar. The string is used to represent the layout of various classes on a three column page of an…
andyface
  • 937
  • 1
  • 9
  • 25
3
votes
3 answers

python scientific notation with forced leading zero

I want to have Python2.7 print out floating point numbers in scientific notation, forced to start with 0. For instance, assume a=1234567890e12 print '{:22.16E}'.format(a) 1.2345678900000000E+21 However, I want a print output that looks…
Ehsan
  • 380
  • 4
  • 9
3
votes
2 answers

Read numbers from file into a dynamically allocated array

I need a function that reads grades (integers) from from file and returns a dynamically allocated array in which they are stored. This is what I have tried: int *readGrades() { int *grades; int x; scanf("%d", &x); grades = malloc(x *…
1
2 3 4