Logo 
Search:

Cobol Articles

Submit Article
Home » Articles » Cobol » Homework HelpRSS Feeds

Program to count particular character for number of times in a input string

Posted By: Evelyn Hughes     Category: Cobol     Views: 5597

Program to count particular character for number of times in a input string

Code for Program to count particular character for number of times in a input string in Cobol

       IDENTIFICATION DIVISION.
         PROGRAM-ID. INS.

       DATA DIVISION.

        01 COUNT1    PIC 99.
        01 INS-NAME PIC X(20) VALUE "APURVA".
        01 CHAR1 PIC XXX.

        01 NEW-NAME PIC X(34).
        01 FULL-NAME.
          02 F-NAME PIC X(10) VALUE "APURVA".
          02        PIC XX.
          02 M-NAME PIC X(10) VALUE "M".
          02        PIC XX.
          02 L-NAME PIC X(10) VALUE "MEHTA".

        01 USTR-NAME PIC X(20) VALUE "APURVA.M.MEHTA".

        01 CH1 PIC 9.
         88 A VALUE 1.
         88 B VALUE 2.
         88 C VALUE 3.
         88 D VALUE 4.

       PROCEDURE DIVISION.
        BEGIN.
          DISPLAY "1.INSPECT.".
          DISPLAY "2.STRING.".
          DISPLAY "3.UNSTRING.".
          DISPLAY "4.EXIT.".
          ACCEPT CH1.

          IF A
            INSPECT INS-NAME TALLYING COUNT1 FOR ALL 'A'
            DISPLAY "NO OF A =" COUNT1
          ELSE IF B
             STRING
               L-NAME DELIMITED BY SIZE
                F-NAME DELIMITED BY SIZE
                 M-NAME DELIMITED BY SIZE
                      INTO NEW-NAME

              DISPLAY NEW-NAME
        
          ELSE IF C
             UNSTRING USTR-NAME
               DELIMITED BY '.'
               INTO L-NAME 
                    F-NAME 
                    M-NAME 
              DISPLAY FULL-NAME
         ELSE
             STOP RUN.


******************************** OUTPUT **********************************

 INSPECT:
      NO OF A =2 
     
 STRING
     MEHTA APURVA M      

 UNSTRING
    
     APURVA M MEHTA
  
Share: 



Evelyn Hughes
Evelyn Hughes author of Program to count particular character for number of times in a input string is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!