473,325 Members | 2,872 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,325 software developers and data experts.

i need help in structures .....

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
8 2690
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Pratts | last post by:
I am a new one who have joined u plz try to help me bcoz i could not find ny sutiable answer foer this Question Qus>>why do we need classes when structures provide similar functionality??
5
by: el_roachmeister | last post by:
For being a good web programmer, is a course on data structures important? It seems php already has built-in functions for what they teach in a data structures course. On the other hand all...
2
by: Dennis Gearon | last post by:
IPU, in place updates. -------------------------- 1/ Put a version numbers on each record represented by a byte/word sized number from a three version number list kept by the table header. This...
6
by: Ken Allen | last post by:
OK, I admit that I have been programming since before C++ was invented, and I have developed more than my share of assembly language systems, and even contributed to operating system and compiler...
14
by: pmclinn | last post by:
I've noticed that many programmers use classes to store data about such things like: Class Customers .....Phone ....ID ....Address End Class....
12
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that...
11
by: efrat | last post by:
Hello, I'm planning to use Python in order to teach a DSA (data structures and algorithms) course in an academic institute. If you could help out with the following questions, I'd sure...
6
by: zaacze | last post by:
hi! am really having trouble with array of structures in c.. i'm quite familiar with structures and arrays and yet am having trouble with a program that would enable to search for a specific record....
4
by: cleanrabbit | last post by:
Hello! I hate having to do this, because im almost certain there is someone in the world that has come across this problem and i just havent found their solution yet, so i do appologise if this...
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...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.