Re: help needed regarding compiling 2 C files
- From: skumar434@xxxxxxxxx
- Date: 18 Aug 2006 10:00:43 -0700
Hi everybody ,
First of all thanks for the suggestion .I have one more question.
How to compile two .C files at once?
let me explain it ..
I have two C files,in the first one i have used the function and in the
second file i have defined the function.
Do i have to compile these files different way ?
thanks in advance
Stan Milam wrote:
skumar434@xxxxxxxxx wrote:
Hi everybody,Why don't you use sprintf() to build the command string? E.G.:
I am faceing problem with strings.
The code is given bellow .In this program i am tring to copy data from
a file into structure .
I am able to copy the data ,but the dat is needed to run some commands
,as u can see i have a string which has the command.
The command is---- chicmd debug 0xB701 0x000000ce3 0xAABBCCDD
I have to repalce the AABBCCDD withe data which is fetched from the
file.
In my program I am tring to fetch one string from the array "cmdbuffer
" the string is "AABBCCDD" with the dat which is fetched form the file
, which is "info->homid".
by using strstr() I am able to fetch the string an replce with it with
the intended one.But its only one time .
char cmdstr[100];
char format[] = "chicmd debug 0xB701 0x000000ce3 0x%s";
.
.
.
sprintf( cmdstr, format, "00815002" );
Replace the string constant above with your input from the file.
I am getting this out put -------
chicmd debug 0xB701 0x000000ce3 0x00815000
00815002
00815002
Segmentation fault
When the progarm comes to 2 nd loop its throughing the segmentation
fault error.
I hope this due to the fact that the data in the array is modified
infirst loop and when strstr chels for the string it returns NULL for
failure .
Can any body suggest me how to over come this problem.
int main( int argc ,char *argv[])
{
int ret_code = 0;
//char l_msg[1024];
char * subptr = NULL;
//char cmdbuffer[150]="chicmd debug 0xB701 0x000000ce3
0xAABBCCDD";
char cmdbuffer[150];
char newcmd[512];
char homid[1024];
int8_t ret_c;
int8_t minimal_res = 1;
int8_t resource_no=4;
int8_t loop_size = 4;
//loop_size = Count_all();
//int8_t offset;
//int8_t str_len;
//resource_no = loop_size;
int counter = 0;
//int8_t res_count_deconfig = 0;
/*ret_c = Doreset();
if ( ret_c != 0)
{
//TCFCOMMENT("unable to reset");
}*/
ret_code = Gethom_id();
while(info->next!=NULL){
if(counter <= loop_size)
{
printf("%s\n",info->homid);
sprintf(homid,"%s",info->homid);
printf("%s\n",homid);
cmdbuffer[150]="chicmd debug 0xB701 0x000000ce3
0xAABBCCDD";
subptr = malloc(sizeof(char));
subptr = strstr(cmdbuffer,"0xAABBCCDD");
printf("hello");
subptr[2]=homid[0];
subptr[3]=homid[1];
subptr[4]=homid[2];
subptr[5]=homid[3];
subptr[6]=homid[4];
subptr[7]=homid[5];
subptr[8]=homid[6];
subptr[9]=homid[7];
sprintf(newcmd,"%s",cmdbuffer);
printf("%s\n",newcmd);
}
counter++;
info=info->next;
}
free(info);
return 0;
}
Thanks in advance
--
Regards,
Stan Milam
=============================================================
Charter Member of The Society for Mediocre Guitar Playing on
Expensive Instruments, Ltd.
=============================================================
.
- Follow-Ups:
- Re: help needed regarding compiling 2 C files
- From: Ben Pfaff
- Re: help needed regarding compiling 2 C files
- From: jmcgill
- Re: help needed regarding compiling 2 C files
- References:
- Help needed for strings
- From: skumar434
- Re: Help needed for strings
- From: Stan Milam
- Help needed for strings
- Prev by Date: Re: finding how much time that is consumed?
- Next by Date: Re: 2004-2006 EXECryptor 2 years uncracked
- Previous by thread: Re: Help needed for strings
- Next by thread: Re: help needed regarding compiling 2 C files
- Index(es):
Relevant Pages
|