473,562 Members | 2,619 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

i need help in structures .....

i need to store the data from a data base in to structure
.............th e 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 2725
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_Keit h) 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_Keit h) 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*******@gma il.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.html for 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.....i t....more..
.....difficult. ...to....read.. ...what....you. ....write.

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_Keit h) 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.html for 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.....i t....more..
....difficult.. ..to....read... ..what....you.. ...write.

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_Keit h) 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
3776
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
2255
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 universities seem to teach this class. I tried taking one but just found it too boring and irrelevant for what I was doing. What are your thoughts?
2
1838
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 would then only involve one more byte per record. This version number list needs to be the VERY first item in the table header. The lowest ordered...
6
4478
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 systems over the years. I have developed code in more than 30 distinct programming languages for a wide cariety of industries. But this issue of...
14
15069
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
3861
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 looked sensible, but it didn't work right. Here is a simple example of what I'm trying to accomplish: // I have a hardware peripheral that I'm...
11
3748
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 appreciate it: 1. What exactly is a Python list? If one writes a, then is the complexity Theta(n)? If this is O(1), then why was the name "list" chosen? If...
6
1432
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. can anybody please do give me a sample of a code that shows searching of records in an array of structures...
4
4701
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 has already been covered. I have been trying to learn c# as fast as possible in the last month and in doing so i have been re-visiting old C/C++...
0
7655
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7869
Oralloy
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. ...
0
8101
jinu1996
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...
0
6221
agi2029
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...
0
5193
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...
0
3608
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2073
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1191
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
903
bsmnconsultancy
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...

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.