Another newbie question:
How do I begin reading data, but starting from the xth line down a
list? In other words, how do I skip the first lines and not read in
those values?
Thanks
--
Posted via http://dbforums.com 15 2193
djj858 <me*********@db forums.com> wrote: How do I begin reading data, but starting from the xth line down a list? In other words, how do I skip the first lines and not read in those values?
[Assuming you're talking about text files]
Unless you're already maintaining an index to your file, the following
applies:
To skip lines you must count them. To count lines you have to count
line delimiters ('newlines'). To count newlines, you have to read the
data, e.g:
/* Untested code! */
#include <stdio.h>
int SkipLines( FILE *fp, unsigned int lines )
{
int c = 0;
while ( lines && (c = fgetc( fp )) != EOF )
if ( c == '\n' )
lines--;
return c == EOF ? 0 : 1;
}
Regards
--
Irrwahn
(ir*******@free net.de)
djj858 <me*********@db forums.com> scribbled the following: Another newbie question:
How do I begin reading data, but starting from the xth line down a list? In other words, how do I skip the first lines and not read in those values?
Usually, you can't. You have to fake it by not caring at the first (x-1)
lines you read. I could be of more help if I knew how you were reading
the data, and from what.
--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"'So called' means: 'There is a long explanation for this, but I have no
time to explain it here.'"
- JIPsoft
Some clarification:
eg of file being read:
REMARK These are some lines of rubbish
REMARK that continue for a while
ATOM 123 123 2312
ATOM 123 123 2312
I want to skip the REMARKs at the beginning and read in the ATOM values.
The way I am doing it at the moment is to manually delete the REMARKs
from the file beforehand and then feeding it into the program using
fscanf. There has to be a better way!
--
Posted via http://dbforums.com
djj858 <me*********@db forums.com> scribbled the following: Some clarification: eg of file being read:
REMARK These are some lines of rubbish REMARK that continue for a while ATOM 123 123 2312 ATOM 123 123 2312
I want to skip the REMARKs at the beginning and read in the ATOM values. The way I am doing it at the moment is to manually delete the REMARKs from the file beforehand and then feeding it into the program using fscanf. There has to be a better way!
There's gotta be a better way, sang Frankie Goes To Hollywood. And there
is. When you have fscanfed from the file to a string, call it s, just
use this kind of mechanism:
if (strncmp(s, "REMARK", 6) == 0) {
/* skip the line */
}
else {
/* actually do stuff with the line */
}
--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Hasta la Vista, Abie!"
- Bart Simpson
djj858 wrote: Some clarification:
eg of file being read:
REMARK These are some lines of rubbish REMARK that continue for a while ATOM 123 123 2312 ATOM 123 123 2312
I want to skip the REMARKs at the beginning and read in the ATOM values. The way I am doing it at the moment is to manually delete the REMARKs from the file beforehand and then feeding it into the program using fscanf. There has to be a better way!
struct atom {
int a, b, c;
} atom[42];
int i = 0;
do {
if (3 == fscanf(f, "ATOM%d%d%d ", &atom[i].a, &atom[i].b, &atom[i].c))
i++;
} while (!feof(f));
Jirka
In <sp************ *************** *****@4ax.com> Irrwahn Grausewitz <ir*******@free net.de> writes: djj858 <me*********@db forums.com> wrote:
How do I begin reading data, but starting from the xth line down a list? In other words, how do I skip the first lines and not read in those values?
[Assuming you're talking about text files]
How do you define a line in a binary file?
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de Da*****@cern.ch (Dan Pop) wrote: In <sp************ *************** *****@4ax.com> Irrwahn Grausewitz <ir*******@free net.de> writes:
[Assuming you're talking about text files]
How do you define a line in a binary file?
In a file format description, which may vary from that of C text
streams.
--
Irrwahn
(ir*******@free net.de)
"Joona I Palaste" <pa*****@cc.hel sinki.fi> schrieb im Newsbeitrag
news:bn******** **@oravannahka. helsinki.fi... djj858 <me*********@db forums.com> scribbled the following:
[....]
There's gotta be a better way, sang Frankie Goes To Hollywood. And there is. When you have fscanfed from the file to a string, call it s, just
^^^^^^^^
Joona, that's great. Seriously
:)))
Robert
In <35************ ****@dbforums.c om> djj858 <me*********@db forums.com> writes: How do I begin reading data, but starting from the xth line down a list? In other words, how do I skip the first lines and not read in those values?
You can't entirely ignore these lines, you must scan the input file for
newline characters, even if you don't attempt to interpret the contents
of the lines in any other way.
The alternative is to have an accompanying index file, containing the
offset of each line of text in the main file, as returned by ftell (or
fgetpos if you have to support very large files). The index file can be
a binary file, so you can immediately compute the offset corresponding
to the information about a certain line number in the main file.
It is very easy, and an excellent exercise for a beginner, to create
and use such an index file, in order to allow the random access to
any line in a plain text file.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dariusz |
last post by:
Below is part of a code I have for a database. While the database table is
created correctly (if it doesn't exist), and data is input correctly into
the database when executed, I have a problem when reading out the data into
the PHP variables / array.
It should be displaying the information out in the following way, using
the PHP array:
n_date, n_headline, n_summarytext, n_fulltext
|
by: Andy |
last post by:
Hi,
In the code below (not pretty I know but it's an early version :-P) I'm
having problems reading the data object back in. If I move the reading
code to immediately after the section where it is written ( commented
out in code) then it reads in OK. However, when I move the code to the
right place ( as shown here) it throws an IO exception. Both the Filter
class and it's constituent class implement Serializable and it would seem
the...
|
by: Magnus |
last post by:
allrite folks, got some questions here...
1) LAY-OUT OF REPORTS
How is it possible to fundamentaly change the lay-out/form of a report in
access? I dont really know it that "difficult", but listen up;
Reports, the way I look at them, all present data downwards, in this way;
TITLE
data
|
by: KevinD |
last post by:
assumption: I am new to C and old to COBOL
I have been reading a lot (self teaching) but something is not sinking
in with respect to reading a simple file - one record at a time.
Using C, I am trying to read a flatfile. In COBOL, my simple file
layout and READ statement would look like below.
Question: what is the standard, simple coding convention for reading
in a flatfile - one record at a time?? SCANF does not work because of...
|
by: arne.muller |
last post by:
Hello,
I've come across some problems reading strucutres from binary files.
Basically I've some strutures
typedef struct {
int i;
double x;
int n;
double *mz;
| |
by: Tyler |
last post by:
Hello All:
After trying to find an open source alternative to Matlab (or IDL), I
am currently getting acquainted with Python and, in particular SciPy,
NumPy, and Matplotlib. While I await the delivery of Travis Oliphant's
NumPy manual, I have a quick question (hopefully) regarding how to read
in Fortran written data.
The data files are not binary, but ASCII text files with no formatting
and mixed data types (strings, integers,...
|
by: blazedaces |
last post by:
Ok, so you know my problem, java is running out of memory reading with SAX, the event-based xml parser intended more-so than DOM for extremely large files. I'll try to explain what I've been doing and why I have to do it. Hopefully someone has a suggestion...
Alright, so I'm using a gps-simulation program that outputs gps data, like longitude, lattitude, altitude, etc. (hundreds of terms, these are just the well known ones). In the newer...
|
by: Shark |
last post by:
Hi,
I need a help. My application reads data from COM port, this data is then
parsed and displyed on:
1. two plotters
2. text box.
I'm using Invoke method to update UI when new data is received (through
delegate).
|
by: swetha |
last post by:
HI Every1,
I have a problem in reading a binary file.
Actually i want a C program which reads in the data from a file which
is in binary format and i want to update values in it.
The file consists of structures of type----
struct record {
int acountnum;
char name;
float value;
|
by: efrenba |
last post by:
Hi,
I came from delphi world and now I'm doing my first steps in C++. I'm
using C++builder because its ide is like delphi although I'm trying to
avoid the vcl.
I need to insert new features to an old program that I wrote in delphi
and it's a good opportunity to start with c++.
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |