By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,209 Members | 1,103 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,209 IT Pros & Developers. It's quick & easy.

i need help in structures .....

P: n/a
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 .

Aug 9 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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.

--
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.
Aug 9 '06 #2

P: n/a
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
............
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


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.

--
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.
Aug 9 '06 #3

P: n/a
sk*******@gmail.com wrote:
>
Please don't top post.
>
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
............
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
Why don't you head Keith's advice and write your question properly?

What have you written so far? All you gave to do is read the file into
an array of structures. Give that a go and come back if you have any
problems.

--
Ian Collins.
Aug 9 '06 #4

P: n/a
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.
Aug 9 '06 #5

P: n/a
I am really sorry guys , now I will try to avoid my bad habbits and
follow your suggestions . Now let me come to my problem , Its some
thing like there is a file (text file) which contains the details of
the system ,like the its unique serial no which is homid and etc which
ever I mentioned earlyer.

This the format of the file .

rid homid type
00810000 00812000 0086 00001000
00810000 00812001 0086 00001000
00810000 00812002 0086 00001001

So I need this data in my progaram and I need only the 2nd column which
is unique for each row.

->I need to define a structure for this so that i can use the value in
my program .
->i need only the rows which contain the hom id which i have passed in
as argument.
-Plz tell me how to fetch data from file using structures?

Thanxs for the suggestions.

Keith Thompson wrote:
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.....wr ite.

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.
Aug 10 '06 #6

P: n/a
sk*******@gmail.com wrote:
I am really sorry guys , now I will try to avoid my bad habbits and
follow your suggestions .
But you haven't - you have top posted again.

Now let me come to my problem , Its some
thing like there is a file (text file) which contains the details of
the system ,like the its unique serial no which is homid and etc which
ever I mentioned earlyer.

This the format of the file .

rid homid type
00810000 00812000 0086 00001000
00810000 00812001 0086 00001000
00810000 00812002 0086 00001001

So I need this data in my progaram and I need only the 2nd column which
is unique for each row.

->I need to define a structure for this so that i can use the value in
my program .
->i need only the rows which contain the hom id which i have passed in
as argument.
-Plz tell me how to fetch data from file using structures?
Follow Keith's excellent psychic advice! There is nothing to add to
Keith's suggestions until you give it a go and post some code.

--
Ian Collins.
Aug 10 '06 #7

P: n/a
Hi there ,
I have tried your suggesetions and hear waht I come up with .
This code is working only for fetching the stating data .
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

struct hom_id{
char nod_de[20];
char hom_id[20];
char hom_type[20];
char hom_pid[20];
};

#define LENTH 4
int main ()

{
FILE *fp;
char buff[200];
int ret;
int read_size;
struct hom_id arr[LENTH];
int i=0;
char* poc_id = "0086";

fp = fopen("momtext.txt","r");
if ( fp == NULL )
{

printf("error");
}
sscanf ( buff , " %s %s %s %s ", &arr[i].nod_de ,
&arr[i].hom_id ,&arr[i].hom_type,&arr[i].hom_pid );

fgets ( buff, 100,fp);

printf("the hom id\t %s \t %s \t %s \t %s \n ",arr[i].nod_de,
arr[i].hom_id, arr[i].hom_type, arr[i].hom_pid );
//}
}

->I am faceing one error for this 0086 , I am getting radix error.
-Can you tell me how to moove in side a file , I need it because
the text file from which I have to fetch data is like this --

00810000 00814945 00c9 0000d005
00810000 00814946 00c9 0000d006
00810000 00814947 00c9 0000d007
00810000 00814948 00c9 0000d008
00810000 00814949 00c9 0000d009
00810000 0081494a 00c9 0000d00a
00810000 0081494b 00c9 0000d00b
00810000 00814960 00c9 0000d00c
00810000 00814961 00c9 0000d00d
00810000 00814962 00c9 0000d00e
00810000 00814963 00c9 0000d00f
00810000 00814964 00c9 0000d010
00810000 00814965 00c9 0000d011
00810000 00814966 00c9 0000d012
00810000 00814967 00c9 0000d013
00810000 00814968 00c9 0000d014
00810000 00814969 00c9 0000d015
00810000 0081496a 00c9 0000d016
00810000 0081496b 00c9 0000d017
00810000 00815000 0044 ffffffff
00810000 00815002 0044 ffffffff
00810000 00815080 0044 ffffffff
00810000 008150c0 0044 ffffffff
00810000 008150c2 0044 ffffffff
00810000 00815180 0044 ffffffff
00810000 008151e0 0044 ffffffff
00810000 008151e1 0044 ffffffff
00810000 00815280 0044 ffffffff

-I have to write a function which will take this 008151e1 as argument
(which is second column in above).
-. So for that i have to search the pattern and copy the lines which
contains the uniqe id 008151e1 to a structure .
-how can I moove inside a file so that I can searech the pattern.
->waht data type i should use to store 008151e1 this type of variable.
-.plz help me .

Ian Collins wrote:
sk*******@gmail.com wrote:
I am really sorry guys , now I will try to avoid my bad habbits and
follow your suggestions .

But you haven't - you have top posted again.

Now let me come to my problem , Its some
thing like there is a file (text file) which contains the details of
the system ,like the its unique serial no which is homid and etc which
ever I mentioned earlyer.

This the format of the file .

rid homid type
00810000 00812000 0086 00001000
00810000 00812001 0086 00001000
00810000 00812002 0086 00001001

So I need this data in my progaram and I need only the 2nd column which
is unique for each row.

->I need to define a structure for this so that i can use the value in
my program .
->i need only the rows which contain the hom id which i have passed in
as argument.
-Plz tell me how to fetch data from file using structures?
Follow Keith's excellent psychic advice! There is nothing to add to
Keith's suggestions until you give it a go and post some code.

--
Ian Collins.
Aug 10 '06 #8

P: n/a
On 10 Aug 2006 09:05:28 -0700, sk*******@gmail.com wrote:
>Hi there ,
I have tried your suggesetions and hear waht I come up with .
This code is working only for fetching the stating data .
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

struct hom_id{
char nod_de[20];
char hom_id[20];
char hom_type[20];
char hom_pid[20];
};

#define LENTH 4
int main ()

{
FILE *fp;
char buff[200];
int ret;
int read_size;
struct hom_id arr[LENTH];
int i=0;
char* poc_id = "0086";

fp = fopen("momtext.txt","r");
if ( fp == NULL )
{

printf("error");
}
sscanf ( buff , " %s %s %s %s ", &arr[i].nod_de ,
&arr[i].hom_id ,&arr[i].hom_type,&arr[i].hom_pid );
No data has been placed in buff. The value of each element of the
array is indeterminate. Evaluating indeterminate values invokes
undefined behavior.

If there were data in buff, each %s promises sscanf that the
corresponding argument is a char*. arr[i].nod_de is an array of 20
char. Applying the & operator to it produces a value of type
char(*)[20]. This type is incompatible with a char*. More undefined
behavior. Fix this problem by removing the &. Ditto for the other
three arguments.
>
fgets ( buff, 100,fp);
This is one statement too late.

Why is buff 200 if you are only reading 100 into it?
>
printf("the hom id\t %s \t %s \t %s \t %s \n ",arr[i].nod_de,
arr[i].hom_id, arr[i].hom_type, arr[i].hom_pid );
You didn't make the & mistake here.
>//}
Are you planning on putting a loop in the code that this brace will
eventually close?
>}
snip sample data and more questions I didn't understand.
Remove del for email
Aug 11 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.