freelanceprogrammers.org Forum Index » C

please help me in the file optimization


View user's profile Post To page top
anup_don2000 Posted: Thu Jul 17, 2003 9:27 am


Joined: 17 Jul 2003

Posts: 1
please help me in the file optimization
Hi experts,
Iam writing a file reading and manipulation program using
c. What I have to do, is to read the keyword and valued froma file,
delimetered with equal sign. Then I want to perform a string
comparison of the keywords, adn then store the value of the
corresponding keyword in to a structure. I will write program as
belows...


int writestruct(char* keyword, char* keyvalue)
{

int i;
char *table []={"ID","NODE","UID","GID"..........81 items}
for (i=0; ; i++) {
if(!strcmp(keyword, table))
break;
}
clrscr();
switch (i)
{
case 0 : strcpy(user.ID, keyvalue);break;
case 1 : strcpy(user.NODE, keyvalue);break;
case 2 : strcpy(user.UID,keyvalue);break;...............

}


The above function to write the corresponding vlaue to the keyword
into structure user , which is previously defined.

***********************************************************************
Now the below function to return the value fro structure at a later time
************************************************************************
char* returnstruct(char* keyword)
{
char* szReturnstruct=malloc(100*sizeof(char));
int i;
char *table []={"ID","NODE","UID","GID"....81 items}

for (i=0; ; i++) {
if(!strcmp(keyword, table))
break;
}
clrscr();
switch (i)
{
case 0 : strcpy(szReturnstruct,user.ID);break;
case 1 : strcpy(szReturnstruct,user.NODE);break;
case 2 : strcpy(szReturnstruct,user.UID);break;
case 3 : strcpy(szReturnstruct,user.GID);break;
}


Now the real problem is that in the for loop( used to return int value
for case structure). Its taking a lot of cpu time and memory.......
Can anyone devise another method ( hash table search and sorting
algorithm implementation is preferred). to get rid of this performance
criteria........Sample code will be greatly appreciated...


Thanks in advance

MS
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help