Click here to Skip to main content
15,891,657 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
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 
Sample File to be parsed and replace different strings..

*************************************************************************
	  * 							API TEMPLATE PROGRAM                      *
	  * THIS PROGRAM SERVES AS A TEMPLATE TO GENERATE THE ACTUAL API PROGRAM  *
	  *                                                                       *
	  * MAPPING RULES: 														  *
	  * --------------------------------------------------------------------  *
	  *		Variable Name						Replace with				  *
	  * --------------------------------------------------------------------  *
	  *     &apiname				API Name from Mapping Repository          *
	  *     &dclgen					DCLGEN name from Mapping Repository       *
	  *     &keyinfo				Key field column name from file layout    * 
	  *     &hostvarprimary			Key field host var name from DCLGEN       *
	  *     &tablecols				Table column name from DCLGEN             *
	  *     &tablehostvars			Host variable names from DCLGEN           *
	  *     &tblprimary				Key field column name from DCLGEN         *
	  *     &tablehostvars01		01 level of host var from DCLGEN          *
	  *************************************************************************  
/* strings to be replaced if present in the above block should be ignored */	  
       IDENTIFICATION DIVISION.
	   PROGRAM-ID. &apiname. /* &apiname string shud be replaced with another string */
	   
	   		EXEC SQL
			INCLUDE &dclgen
		END-EXEC.
	   
		EXEC SQL
			INCLUDE SQLCA
		END-EXEC.
	   
	 	   2100-SELECT-PARA.
			MOVE &keyinfo TO &hostvarprimary
			EXEC SQL
				SELECT &tablecols /* &tablecols to be replaced with another string */
					INTO
					&tablehostvars /*&tablehostvars to be replaced with another string */


					FROM &tblname
					WHERE
					&tblprimary = &hostvarprimary
			END-EXEC
			IF SQL-CODE EQUAL ZERO
				SET FUNC-SUCCESS	TO TRUE
				MOVE &tablehostvars01 TO VSAM-REC-BLOCK
			ELSE
				PERFORM 9999-ABEND-PARA
			END-IF.
	   2100-SELECT-PARA-EXIT. EXIT.

	   2200-INSERT-PARA.
			MOVE VSAM-REC-BLOCK TO &tablehostvars01 /* This &tablehostvars01 string SHOULD NOT be replaced.. */
			EXEC SQL
				INSERT INTO &tblname
				(
				&tablecols
				)
				VALUES
				(
				&tablehostvars
				)
			END-EXEC
			IF SQL-CODE EQUAL ZERO
				SET FUNC-SUCCESS	TO TRUE
			ELSE
				PERFORM 9999-ABEND-PARA
			END-IF.
	   2200-INSERT-PARA-EXIT. EXIT.	   
			
	   2300-UPDATE-PARA.
			MOVE VSAM-REC-BLOCK TO &tablehostvars01 /* shud not be replaced */
			EXEC SQL
				UPDATE &tblname
				SET &tablecols = :&tablehostvars
					WHERE
					&tblprimary = &tablehostvarsprimary /* shud not be replaced */
			END-EXEC
			IF SQL-CODE EQUAL ZERO
				SET FUNC-SUCCESS	TO TRUE
			ELSE
				PERFORM 9999-ABEND-PARA
			END-IF.
	   			EXIT PROGRAM.


I shall paste below my exact replace function too
replace(char text2find[80],char text2repl[80],char fileOrig[32], char fileRepl[32] )
{

	    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+");
	    rewind(fp1);
	    rewind(fp2);

	    while(fgets(buffer,MAX_LEN_SINGLE_LINE+2,fp1))
	    {
	        buff_ptr = buffer;
	        tok = strtok(buff_ptr,"*");
	        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);
	        }
	    }

	   fclose(fp2);
	   fclose(fp1);
}




Thanks,
Faez
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 
GeneralRe: I need gSpan source code ( C or C++ ) Pin
Albert Holguin12-Feb-12 9:13
professionalAlbert Holguin12-Feb-12 9:13 
QuestionCognizance Presents Insomnia : The Nocturnal Coding Life Pin
insomniaiitr10-Feb-12 23:05
insomniaiitr10-Feb-12 23:05 
QuestionRegister your program as PC's antivirus Pin
Brandon-X1200010-Feb-12 17:49
Brandon-X1200010-Feb-12 17:49 
AnswerRe: Register your program as PC's antivirus Pin
«_Superman_»12-Feb-12 17:55
professional«_Superman_»12-Feb-12 17:55 
GeneralRe: Register your program as PC's antivirus Pin
Brandon-X1200012-Feb-12 22:30
Brandon-X1200012-Feb-12 22:30 

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.