Hi Anthony/All;
Based on my previous mail I have made a few changes in the code,
Problem:
if a <Matching Tags> is found , <Repalcing strings> is placed in the
next line not in the same line. I mean there is a shift, pl have a look
and run the code with some file as:
Temp.txt:
DEAD MAN=HAPPY MAN
FOX IP=192.168.1.1
Current code when executed:
#./a.out "DEAD MAN" "00.00.00.00.00.00"
the "Temp.txt" file shows
DEAD MAN=HAPPY MAN
FOX IP=00.00.00.00.00.00
Kindly find the code!
#include <stdio.h>
int main (int argc , char **argv)
{
FILE *fp ;
int c, rep, i ;
char buf[100];
int location;
if ( argc != 3 ) {
printf ( "Usage : %s : <Matching Tags> <replace_string>\n" ,
argv[0] ) ;
exit (1);
}
if ( ( fp = fopen ( "Temp.txt" , "r+" ) ) == NULL ) {
fprintf ( stderr , "Error in opening the file\n" );
exit (1);
}
rep = 0; i = 0; location=1;
while(fgets(buf, 1000, fp)!=NULL)
{
if(strstr(buf, argv[1])!=NULL)
{
while ((c = fgetc(fp))!=EOF ) {
if (c == '=' ) {
while ( argv[2][i]!= '\0' ) {
fprintf ( fp , "%c" , argv[2][i], '\n');
i++;
}
rep = 1;
}
if ( rep );
}
location++;
}
if (location==1);
}
fclose(fp);
return 0;
}
-raja
On Wed, 2005-02-09 at 19:04, Noorul Islam wrote:
why dont you try sed.
ilugc-bounces@xxxxxxxxxxxxx wrote on 02/09/2005 07:12:12 PM:
Thanks, I sorted it out.. for some unseen character not shown in VIM
editor..
B.t way..I would like to add the functionality..some what like this..
./a.out <Matching Tags> <Replacing Strings>
as argv[1] and argv[2]..
The program take input <Matching Tags> i.e argv[1] to search for any
matching parameter in a particular line.
If it finds that <Matching Tags> preceed with "=" in the file, then that
line should be over written as
<Matching Tags>=<Replacing Strings> for all lines that matches the
<Matching tags> i.e argv[1]
Current the program you sent is writing any string passed just when it
encounters first "=" character and appends the string next to it..
Thanks for your mail..
Regards
Raja Mallik
On Wed, 2005-02-09 at 18:59, Anthony Ashok wrote:
Hi,
in my system I didn't get any error whil compiling .,
In which OS you are compiling . Please include the header files which
are necessary in your system.
I am using RH 9 so i din't get any pblm
Incase If you find Problem pl ring me at 984177482
bye
with warm regards,
Anthony Jesu Ashok S Ext : 7257
Raja Mallik
<raja.mallik@xxxxxxxxxxx>
02/09/2005 06:30 PM
To:
Anthony Ashok
<Anthony.Ashok@xxxxxxxxxxxxxxx>
cc:
ilugc@xxxxxxxxxxxxx
Subject:
Re: [Ilugc] RE: C help?
Hi Anthony!
Thanks for the mail..
wow! while complining I get
NewFindTags.c:31: stray '\302' in program
NewFindTags.c:31: stray '\240' in program
NewFindTags.c:33: stray '\302' in program
NewFindTags.c:33: stray '\240' in program
I have never seen this..
-raja
On Wed, 2005-02-09 at 18:13, Anthony Ashok wrote:
Hi,you need
As per the Understanding from the requirement I have done this If
any Addition please tell me so that I can do that for you.______________________________________________________________________
Thanx
# include <stdio.h>
main (int argc , char **argv )
{
FILE *fp ;
int c, rep, i ;
if ( argc != 2 ) {
printf ( "Usage : %s : <replace_string>\n" , argv[0] ) ;
exit (1);
}
if ( ( fp = fopen ( "temp1" , "r+" ) ) == NULL ) {
fprintf ( stderr , "Error in opening the file\n" );
exit (1);
}
rep = 0; i = 0;
while ( ( c = getc ( fp ) ) != EOF ) {
if ( c == '=' ) {
while ( argv[1][i] != '\0' ) {
fprintf ( fp , "%c" , argv[1][i] ); i++;
}
rep = 1;
}
if ( rep ) fprintf ( fp , "%c" , ' ' ) ;
}
fclose(fp);
}
with warm regards,
Anthony Jesu Ashok S Ext : 7257
_______________________________________________
To unsubscribe, email ilugc-request@xxxxxxxxxxxxx with
"unsubscribe <password> <address>"
in the subject or body of the message.
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
______________________________________________________________________
______________________________________________________________________
_______________________________________________
To unsubscribe, email ilugc-request@xxxxxxxxxxxxx with
"unsubscribe <password> <address>"
in the subject or body of the message.
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc