help me plz i am really in need of solution

S

skumar434

ts 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.

This code is working only for fetching the stating data .

#include <stdio.h>
#include <string.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.nod_de ,
&arr.hom_id ,&arr.hom_type,&arr.hom_pid );

fgets ( buff, 100,fp);

printf("the hom id\t %s \t %s \t %s \t %s \n ",arr.nod_de,
arr.hom_id, arr.hom_type, arr.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 .
 
F

Flash Gordon


-.plz help me .

I might have done, but not only are you using stupid contractions such
as plz making it harder to read you post, but you have also posted what
looks like the same query within a few hours of first posting it. You
should wait at *least* a day before assuming no one will respond since
whatever time you post some people will be asleep, some at work etc
since we are from all over the world. Also it can take time for messages
to propagate.
 
M

Michael Mair

ts 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.

??? homid?
This code is working only for fetching the stating data .

Do you mean starting data?
#include <stdio.h>
#include <string.h>
#include <unistd.h>

My compiler does not know this header.
struct hom_id{
char nod_de[20];
char hom_id[20];
char hom_type[20];
char hom_pid[20];
};

It is allowed in C to have
struct foo {
struct {
int foo;
} foo;
} foo;
but it is a good idea to avoid to many equal identifiers.
#define LENTH 4
int main ()

Make it explicit:
int main (void)
{
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");

Usually, it is better to separate "normal" and error output:
fprintf(stderr, "error\n");

You have opened the file, now you should read stuff.
sscanf ( buff , " %s %s %s %s ", &arr.nod_de ,
&arr.hom_id ,&arr.hom_type,&arr.hom_pid );

fgets ( buff, 100,fp);


Wrong order.
First you try to read stuff into buff, then you make sure that
something arrived there and only afterwards you try to sscanf()
data.
Note that you should make sure that sscanf() successfully converted
the data by having a look at its return value.
Using %s without size limits invites buffer overflows.
As you have hex numbers of at most eight digits, "%lx" to
read into an unsigned long may be the better choice in your case.
printf("the hom id\t %s \t %s \t %s \t %s \n ",arr.nod_de,
arr.hom_id, arr.hom_type, arr.hom_pid );
//}


Note: pre-C99 compilers do not have to accept // comments.

You forgot
return 0;
}

->I am faceing one error for this 0086 , I am getting radix error.

At which point in your source.
-> 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 00815280 0044 ffffffff

Use getc to advance by one position, fgetpos() to get an object
of type fpos_t describing the current position, fsetpos() to
navigate to a position using an object previously obtained from
a fgetpos() call and rewind() to move to the start of the file.
These are the most basic functions (and macros) but not necessarily
the worst way.
-> 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 .

Okay, then move the functionality of scanning a line for "008151e1"
to a function of its own.
Another function gets the lines and feeds it to the first function.
-> 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.

See above.
unsigned long
and sufficiently large arrays of char are good candidates --
depending on how the pattern can look in the end.


Cheers
Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top