sk*******@gmail.com writes:
Keith Thompson wrote:
>sk*******@gmail.com writes:
i need to store the data from a data base in to structure
............the problem is like this ....suppose there is a data base
which stores the sequence no and item type etc ...but i need only the
sequence nos and it should be such that i can access it through the
structure .plz help me .
Your question is unclear, at least in part because your punctuation
and grammar are unclear. Please use proper capitalization and
spelling, and don't use "..." to indicate the end of a sentence. For
example:
I need to store the data from a data base into a structure. The
problem is like this. Suppose there is a data base which stores
the sequence number and item type, etc., but I need only the
sequence numbers, and it should be such that I can access it
through the structure. Please help me.
That's *much* easier to read.
Now, as for your actual question:
Interaction with databases (SQL, whatever) is off-topic here. If
that's what you're asking about, try a newsgroup that deals with
whatever database you're using.
Apart from that, it just sounds like you want to store a list of
sequence numbers, which sounds like a job for a simple array of
integers.
i should have fully explained what i want..........
i have a text file which has four coulms of data .i have to create a
structure and access that data throuh that structiure..........one more
problem is that i need to extract the required data for example 4 rows
...........
Please don't top-post; I've corrected it here. See
<http://www.caliburn.nl/topposting.htmlfor more information.
You should always quote some context when posting a followup, but it's
rarely necessary to quote the *entire* article to which you're
responding. Take the time to trim anything that's not relevant to
your followup; leave enough quoted material so the followup makes
sense on its own. In particular, don't qoute signatures unless you're
commenting on them.
Please capitalize the word "I" and the first word of each sentence.
Your shift key exists for a very good reason. And please stop using
long rows of '.' characters. They......just......make.....it....more..
.....difficult....to....read.....what....you.....w rite.
I'm not just being picky here. We're not going to jump on you for
minor errors in spelling and grammar, but if you make some effort to
write in standard English, it really does make it easier to read what
you write -- especially for people for whom English is not a first
language. If you want our help, it's *your* responsibility to
communicate clearly.
here is total --
4 colums ---node id ,hom id ,hom type and resource id
typedef structure {
usingned nodeid;
unsigned homid;
unsigned homty;
unsigned resid;
}
i want access the data in the file through this structure .plz help me
The following is my *guess* about what you're doing.
You have an input text file, each line of which has 4 pieces of
information, called "node id", "hom id", "hom type", and "resource
id". I don't know what these look like; if they're separated by
blanks, and don't themselves contain blanks, it will make the job
easier.
You want to read the file and store information from each line in a
structure something like what you've written above. Since the members
of the structure are of type unsigned, I'm guessing the fields in your
input file are numeric literals, sequences of decimal digits.
If you actually told us what you're dealing with, I wouldn't have to
guess. (I don't *have* to guess anyway, but the alternative is to
ignore your question.)
If this is what your file looks like, you can probably use fgets() to
read each line, then sscanf() to extract the fields. Don't use
sscanf() with a plain "%s" format; that allows any overly long input
to clobber your program. You can use, for example, "%10s" to read a
word (a whitespace-delimited substring) of at most 10 characters. You
can store the results in the members of your structure. You'll
probably need to use some method to allocate a number of structures;
you can set up a linked list, or you can declare a fixed-size array,
or you can allocate a dynamically-sized array using malloc() (and, if
necessary, expand it using realloc()).
Always check the value returned by any function you call. For
example, sscanf() returns the number of items it successfully scanned;
use this result to verify that there weren't any errors. (How you
handle errors if they occur is up to you; the simplest, and crudest,
solution is to abort the program with an error message.)
Read the documentation for these functions to find out how they work.
Now, for all I know from your description, you could be reading a
binary file rather than a text file, or the columns could be
represented in hexadecimal or Roman numerals. Define *exactly* what
the program is supposed to do before you write it.
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.