Click here to Skip to main content
16,005,467 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Create process & IE Pin
_Flaviu15-Feb-12 19:41
_Flaviu15-Feb-12 19:41 
AnswerRe: Create process & IE Pin
Chuck O'Toole16-Feb-12 4:35
Chuck O'Toole16-Feb-12 4:35 
QuestionTCP/IP socket timeout per connection Pin
vikramlinux13-Feb-12 4:17
vikramlinux13-Feb-12 4:17 
AnswerRe: TCP/IP socket timeout per connection Pin
Albert Holguin13-Feb-12 4:38
professionalAlbert Holguin13-Feb-12 4:38 
GeneralRe: TCP/IP socket timeout per connection Pin
vikramlinux13-Feb-12 4:44
vikramlinux13-Feb-12 4:44 
GeneralRe: TCP/IP socket timeout per connection Pin
Albert Holguin13-Feb-12 6:22
professionalAlbert Holguin13-Feb-12 6:22 
GeneralRe: TCP/IP socket timeout per connection Pin
vikramlinux13-Feb-12 22:27
vikramlinux13-Feb-12 22:27 
QuestionHow to re-use the replace() function to replace different strings in the same file ? Pin
Faez Shingeri13-Feb-12 0:12
Faez Shingeri13-Feb-12 0:12 
Hi,
I have a replace function which replaces all the occurences of the string into another file. But when I use the replace function multiple times... it replaces the string which was passed in the last call only and all the previous replacement does not happen.
Below is the code
replace(char text2find[80],char text2repl[80])
 {

        char fileOrig[32] = "OrigFile.txt";
 	char fileRepl[32] = "ReplacedFile.txt";
 	   
        char buffer[MAX_LEN_SINGLE_LINE+2];
 	char *buff_ptr, *find_ptr, *tok;
 	FILE *fp1, *fp2;
 	size_t find_len = strlen(text2find);

 	fp1 = fopen(fileOrig,"r");
 	fp2 = fopen(fileRepl,"w+");


 	while(fgets(buffer,MAX_LEN_SINGLE_LINE+2,fp1))
 	    {
 	        buff_ptr = buffer;
 	        tok = strtok(buff_ptr,"*");//ignores the string occurence after *
 	      if(tok != NULL)
 	       {
 	        	while ((find_ptr = strstr(buff_ptr,text2find)))
 	        	{

 	        		while(buff_ptr < find_ptr)
 	                fputc((int)*buff_ptr++,fp2);

 	        	fputs(text2repl,fp2);

 	            buff_ptr += find_len;

 	        	}
 	        	fputs(buff_ptr,fp2);
 	       }
 	    }
 	    rewind(fp1);
 	    rewind(fp2);
 	    fclose(fp2);
 	    fclose(fp1);
 }

I wud actually wanto replace all the string in the same file, but am finding it tough and also reuse of the replace function multiple times wud be difficult. Hence went with two files...


Thanks,
Faez
AnswerRe: How to re-use the replace() function to replace different strings in the same file ? Pin
Luc Pattyn13-Feb-12 2:36
sitebuilderLuc Pattyn13-Feb-12 2:36 
GeneralRe: How to re-use the replace() function to replace different strings in the same file ? Pin
David Crow13-Feb-12 2:43
David Crow13-Feb-12 2:43 
GeneralRe: How to re-use the replace() function to replace different strings in the same file ? Pin
Faez Shingeri13-Feb-12 18:33
Faez Shingeri13-Feb-12 18:33 
GeneralRe: How to re-use the replace() function to replace different strings in the same file ? Pin
David Crow14-Feb-12 3:13
David Crow14-Feb-12 3:13 
GeneralRe: How to re-use the replace() function to replace different strings in the same file ? Pin
Faez Shingeri14-Feb-12 16:58
Faez Shingeri14-Feb-12 16:58 
QuestionRe: How to re-use the replace() function to replace different strings in the same file ? Pin
David Crow15-Feb-12 3:01
David Crow15-Feb-12 3:01 
QuestionWrite a C/C++ program that connects to a MySQL server and displays the global TIMEZONE Pin
manmadkumarreddy12-Feb-12 7:50
manmadkumarreddy12-Feb-12 7:50 
AnswerRe: Write a C/C++ program that connects to a MySQL server and displays the global TIMEZONE Pin
Richard Andrew x6412-Feb-12 7:55
professionalRichard Andrew x6412-Feb-12 7:55 
AnswerRe: Write a C/C++ program that connects to a MySQL server and displays the global TIMEZONE Pin
Richard MacCutchan12-Feb-12 8:12
mveRichard MacCutchan12-Feb-12 8:12 
AnswerRe: Write a C/C++ program that connects to a MySQL server and displays the global TIMEZONE Pin
Mohibur Rashid12-Feb-12 18:04
professionalMohibur Rashid12-Feb-12 18:04 
AnswerRe: Write a C/C++ program that connects to a MySQL server and displays the global TIMEZONE Pin
Wes Aday13-Feb-12 3:03
professionalWes Aday13-Feb-12 3:03 
QuestionI need gSpan source code ( C or C++ ) Pin
linnumberone12-Feb-12 1:31
linnumberone12-Feb-12 1:31 
AnswerRe: I need gSpan source code ( C or C++ ) Pin
Richard MacCutchan12-Feb-12 1:41
mveRichard MacCutchan12-Feb-12 1:41 
GeneralRe: I need gSpan source code ( C or C++ ) Pin
linnumberone12-Feb-12 1:48
linnumberone12-Feb-12 1:48 
GeneralRe: I need gSpan source code ( C or C++ ) Pin
Richard MacCutchan12-Feb-12 3:04
mveRichard MacCutchan12-Feb-12 3:04 
GeneralRe: I need gSpan source code ( C or C++ ) Pin
linnumberone12-Feb-12 3:31
linnumberone12-Feb-12 3:31 
GeneralRe: I need gSpan source code ( C or C++ ) Pin
linnumberone12-Feb-12 3:53
linnumberone12-Feb-12 3:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.