Home   Easy-Code    Forum  Updater 
Twitter Facebook



Program to find a particular character and replace every occurence of it by another character using cobol

Critics Rating:

Users Rating:

* PROGRAM TO FIND A PARTICULAR CHARACTER AND REPLACE EVERY OCCURENCE OF

* IT BY ANOTHER CHARACTER.

***********************************************************************

   IDENTIFICATION DIVISION.

   PROGRAM-ID.

   ENVIRONMENT DIVISION.

   INPUT-OUTPUT SECTION.

   FILE-CONTROL.

      SELECT DATAFILE ASSIGN TO DISK

      ORGANIZATION IS LINE SEQUENTIAL.

   DATA DIVISION.

   FILE SECTION.

   FD DATAFILE

      LABEL RECORDS ARE STANDARD

      VALUE OF FILE-ID IS "CHAR.DAT".

   01 CHAR.

    02 C PIC A.

   WORKING-STORAGE SECTION.

   77 A PIC A VALUE " ".

   77 EOF PIC A VALUE "Y".

   77 CH PIC A.

   77 S PIC A.

   PROCEDURE DIVISION.

   MAIN-PARA.

      DISPLAY "ENTER THE TEXT CHARACTER BY CHARACTER"

                  " ENDING WITH "$"".

      OPEN OUTPUT DATAFILE.

      PERFORM A-PARA UNTIL A = "$".

      CLOSE DATAFILE.

      DISPLAY "ENTER THE CHARACTER TO BE SEARCHED".

      ACCEPT S.

      DISPLAY "ENTER THE CHARACTER TO BE REPLACED".

      ACCEPT CH.

      OPEN I-O DATAFILE.

      DISPLAY "THE REPLACED TEXT IS AVAILABLE"

               " IN CHAR.DAT FILE".

   PERFORM X-PARA UNTIL EOF = "N".

      CLOSE DATAFILE.

      STOP RUN.

   A-PARA.

      ACCEPT A.

      WRITE CHAR FROM A.

   X-PARA.

      READ DATAFILE RECORD AT END MOVE "N" TO EOF.

      IF (EOF NOT = "N")

       IF (C = S)

       MOVE CH TO C   

       REWRITE CHAR.

      ADD 1 TO COL.

Courtesy, Source, References & Regards: Kishore AVGK

While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright@2009-2011 by KuGuNi.com. All Rights Reserved.