This is the code i have written to replace a line which contains GATEWAY. -
#include<stdlib.h>
-
#include <string.h>
-
#define IF_CONF "ifffcccccc.txt"
-
main()
-
{
-
char line[130],line1[130];
-
-
FILE *fp=NULL,*ofp=NULL;
-
fp=fopen(IF_CONF,"rw+");
-
ofp=fopen(IF_CONF,"rw+");
-
if(fp==NULL)
-
{
-
printf("\n\nerror\n");
-
return -1;
-
}
-
while (fgets(line,sizeof(line),fp))
-
{
-
-
printf("Line Read: %s\n",line);
-
if(strstr(line, "GATEWAY") != NULL)
-
{
-
fclose(fp);
-
printf("Replacing\n");
-
strcpy(line,"GATEWAY=");
-
strcat(line,"111.111.111.111\n");
-
printf("%s",line);
-
fseek(ofp,0,SEEK_CUR);
-
fputs(line,ofp);
-
printf("\nReplace Over\n");
-
break;
-
-
}
-
-
-
}
-
-
fgets(line1,sizeof(line1),ofp);
-
}
-
-
printf("The line = %s\n\n\n",line);
-
fclose(ofp);
-
return 0;
-
}
-
The problem it is deleting the next line charecters.
The file "ifffcccccc.txt" contains
AAAAAAAAAAAAAAAAA
BBBBBBBBBBBBBBBB
DDDDDDDDDDDDDD
GATEWAY=191.1.51.21
HELLO
HKKKKKKK
Please any one help..
5 2347
You got this to compile? What compiler/version? I can't even get it to compile with cygwin gcc v 3.4.4
hi,
u cant modify contents of a file once it is open.. wat u can do it rewrite the whole content once again.. and fclose the file.
Regards
Xoinki
You got this to compile? What compiler/version? I can't even get it to compile with cygwin gcc v 3.4.4
ya i am able to complile it..
hi,
u cant modify contents of a file once it is open.. wat u can do it rewrite the whole content once again.. and fclose the file.
Regards
Xoinki
I am able to modify it , but the problem is , i am not able to write to a line more than the string length of the original contents of the line.if i write like that the next line contents is overwritten.
I am able to modify it , but the problem is , i am not able to write to a line more than the string length of the original contents of the line.if i write like that the next line contents is overwritten.
Right, well, apparently you're not going to share your compiler or version, so why not read the entire file in, close it (still holding the file contents in memory), and then open a new file output stream and write the data you need?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: - ions |
last post by:
Hi, i would like to know how to replace every char in a string with a
certin given char using the String.replace(char oldChar,char newChar).
I would like to replace all letters with an underscore...
|
by: Daniel |
last post by:
I use an Access database to basically take data exports, import them,
manipulate the data, and then turn them into exportable reports. I do
this using numerous macros, and queries to get the data...
|
by: adam lital |
last post by:
Hi,
I have word document and i want to replace a specific text with a bookmark
using code.
Example:
in the document i have the text and i want to replace this to a
bookmark called ClientName....
|
by: Balakrsihna |
last post by:
Hi All,
Can anyone tell me how to replace an image in MS Word 2003 using c#.net.
I am converting an html file to word doc and sending this as attachment
using System.Web.Mail; the...
|
by: James Vitale |
last post by:
Using vb asp.net 1.1
I'm doing a word automation on a doc file and trying to do a find and
replace. My existing code works fine except that it doesn't find and
replace in the header.
My code...
|
by: Casey |
last post by:
Hello,
Can someone give me specific code to replace text on a page using
server side javascript? I need to use server-side because I need the
output to be recognized in the final HTML so that...
|
by: Xah Lee |
last post by:
Interactive Find and Replace String Patterns on Multiple Files
Xah Lee, 2006-06
Suppose you need to do find and replace of a string pattern, for all
files in a directory. However, you do not...
|
by: Michael Yanowitz |
last post by:
Hello:
I am hoping someone knows if there is an easier way to do this or someone
already implemented something that does this, rather than reinventing the
wheel:
I have been using the...
|
by: Ola K |
last post by:
Hi guys,
I wrote a script that works *almost* perfectly, and this lack of
perfection simply puzzles me.
I simply cannot point the whys, so any help on it will be appreciated.
I paste it all here,...
|
by: senthil2ganesh |
last post by:
How to replace a word in a file contain with other word.For example
If the file contain word like %,This % is should replace with %.
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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...
| |