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

read integers from unknown no. of lines

i want to write a C pgm that reads integers from the file which contain unknown no. of integers in each of unknown no. of lines. i want to execute the ogm in linux.
Nov 3 '07 #1
6 3309
weaknessforcats
9,208 Expert Mod 8TB
What is your question? I understand what you want to do but you haven't said where you are stuck.
Nov 3 '07 #2
What is your question? I understand what you want to do but you haven't said where you are stuck.

the no. of integers in a line is not known. so i cant give a limit and loop the " fscanf " no. of times. this my prblem. wat is the solution ???
Nov 7 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
fscanf() will read one integer at a time.

why are you concerned with the number of integers on a line??

fscanf() is for formatted input where you already know the type of data coming in. That is, fcanf() skips all whitepspace-and that includes the end of line marker.

If you don't, or have to know how many integrs per line, then you have to use code that reads by byte and assembles your integers a byte at a time. That is, you get() into an array and create your integer from the array when you get() a non-digit. This way you can detect the end of line marker.
Nov 7 '07 #4
fscanf() will read one integer at a time.

why are you concerned with the number of integers on a line??

fscanf() is for formatted input where you already know the type of data coming in. That is, fcanf() skips all whitepspace-and that includes the end of line marker.

If you don't, or have to know how many integrs per line, then you have to use code that reads by byte and assembles your integers a byte at a time. That is, you get() into an array and create your integer from the array when you get() a non-digit. This way you can detect the end of line marker.


i want to solve a problem in which no. of trial cases is not given directly. each line of integers( no.of integers < 30 ) makes one test case. i want to read each line and process it and write result to output file. i dont know how to identify the end of line marker. please explain it clearly.... plz
Nov 7 '07 #5
weaknessforcats
9,208 Expert Mod 8TB
You should be able to check for \n to detect the end of line.
Nov 7 '07 #6
RRick
463 Expert 256MB
You simply do exactly what you describe.
i want to read each line
fgets does that and will put the line of data in a buffer.
process it
I assume you mean to read each integer in the line. Use sscanf to read the integers from the buffer. You'll need to loop sscanf over the buffer until you read all the integers.
Nov 7 '07 #7

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

Similar topics

16
by: aruna | last post by:
Given a set of integers, how to write a program in C to sort these set of integers using C, given the following conditions a. Do not use arrays b. Do not use any comparison function like if/then...
19
by: ranjeet | last post by:
Hay Guys can you all suggest me the points on the below issue Problem : The thing is that I have the data some thing like this. 1486, 2168, 3751, 9074, 12134, 13944, 17983, 19173, 21190,...
22
by: none | last post by:
If I need to add up all integers in a line (they're separated by space) How can I do that?? e.g. input : 1 4 5 2 3 sum : 15 input : 2 3 sum: 5
5
by: Lars-Erik Aabech | last post by:
Hi! Guess it's my day again.. Tried to deploy a test release of a new asp.net web today, and got a terrible error. The web is running swell on three development computers, but when it's copied...
24
by: rudranee | last post by:
hi there, can anyone tell me how to lines from a file which are odd numbered i.e. 1st,3rd,5th...lines. i tried incrementing file pointer by 2 (fp=fp+2) but it does'nt work Can someone give me...
2
by: dispatch4599 | last post by:
I'm only a beginner in C++ and can not figure out how to read only 2 lines of my infile. The lines consist of all integers. Objective is to add all the integers in just those two lines and average...
6
by: rohit | last post by:
Hi All, I am new to C language.I want to read integers from a text file and want to do some operation in the main program.To be more specific I need to multiply each of these integers with another...
63
by: Bill Cunningham | last post by:
I don't think I can do this without some help or hints. Here is the code I have. #include <stdio.h> #include <stdlib.h> double input(double input) { int count=0,div=0; double...
4
by: omono84 | last post by:
I know that this should be rather simple but i seem to be missing a step to get it to work. and have been unable to find a solution on the net. The aim is that I click on the open button to find...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.