473,462 Members | 1,333 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

help me plz i am really in need of solution

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

Aug 10 '06 #1
2 1268
sk*******@gmail.com wrote:
ts some
<snip>
-.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.
--
Flash Gordon
Still sigless on this computer.
Aug 10 '06 #2
sk*******@gmail.com schrieb:
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[i].nod_de ,
&arr[i].hom_id ,&arr[i].hom_type,&arr[i].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[i].nod_de,
arr[i].hom_id, arr[i].hom_type, arr[i].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
<snip>
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
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Aug 10 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Jeff Louie | last post by:
Well I wonder if my old brain can handle threading. Dose this code look reasonable. Regards, Jeff using System; using System.Diagnostics; using System.IO; using System.Threading;
23
by: vinod.bhavnani | last post by:
Hello all, I need desperate help Here is the problem: My problem today is with multidimensional arrays. Lets say i have an array A this is a 4 dimensional static array.
83
by: deppy_3 | last post by:
Hi.I am started learning Programm language C before some time.I am trying to make a programm about a very simple "sell shop".This programm hasn't got any compile problem but when i run it i face...
16
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.