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

How to scan multiple lines using scanf when we dont know the end of input ?

I referred this link ,but I am unable to get the logic behind using %[^\n]%*c or %[^\t] as format specifier .

http://stackoverflow.com/questions/14494309/reading-multiple-lines-of-input-with-scanf

And how to scan multiple lines of input when we don't know the end of input , say in those cases where we have an online compiler which would be giving its own input test cases which can be of any length and we are asked to perform some operation on that input so how will we determine how to scan the input since there we don't know the end of input ?
Aug 24 '16 #1
4 4344
donbock
2,426 Expert 2GB
Refer to the man page for fscanf().
%[^\n] and %[^\t] are examples of the negated scanset specifier where the scansets are \n (newline) and \t (tab) respectively.
%*c is an example of the character specifier with the asterisk sub-specifier.

A serious problem with your examples is the risk that the string filled by the negated scanset could overflow.
Aug 25 '16 #2
weaknessforcats
9,208 Expert Mod 8TB
You will need to supply and end-of-data signal that you can use in the function with the scanf. My suggestion is to use something not in your data to begin with: \\EOD\\ or some such.

No one ever knows when all the data has been received.
Aug 25 '16 #3
donbock
2,426 Expert 2GB
You can compare the fscanf() return value to EOF.
You can call feof() and/or ferror() after each call to fscanf().
Aug 26 '16 #4
weaknessforcats
9,208 Expert Mod 8TB
Testing EOF is a design decision. EOF does not mean all the data has been received. It just means the current input file has reached
end-of-file.

Input may span several files.
Aug 27 '16 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: raghuveer | last post by:
i want to implement multiple stacks using arrays..I am able to create ,insert and print them but not poping an element form any of the stack..This is what i have #include<stdio.h>...
5
by: dubing | last post by:
Hi, We have some html source like this: <div class="survey"> <form action="students/cbe-graduate-students/survey.html" method="post" id="frmPbSurvey"> <fieldset class="survey_item">...
4
by: arizal | last post by:
Hi , I am trying to figure out why my PHP code to delete multiple value by selecting the checkbox is not working. My php code is listed as below <?php $sql = "Select * from list;";...
4
by: thanawala27 | last post by:
hi, i wanted to know how to comment multiple lines in a perl program say in this piece of code. for ($i=0; $i<5; $i++) { print "<tr> <td width=10%>
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
5
by: =?Utf-8?B?TWlrZSBE?= | last post by:
This is a difficult question: I need to be able to input data via hand-scanner into a web page textbox, but it needs to be done more than once. The user will scan one card after another and in the...
7
by: chaitanya83 | last post by:
How to select text which is in multiple lines on clicking more than twice? I have scenario like this: eg:-6118051 Non-Receipt Per web, delivery incomplete. Request trace and driver followup...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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.