string manipulation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • spanky
    New Member
    • Oct 2006
    • 2

    #1

    string manipulation

    please help me,i'm given a task of writing a program,that ask the user to enter a sting,and then it output the number each letter is appearing,in the string.

    example of output:
    Enter a string:YOU ARE BEAUTIFUL
    A=2 appearance(s)
    B=1appearance(s )
    C=0 appearance(s)
    D=0 appearance(s)

    and so on up to letter 'Z'.
  • Karan
    New Member
    • Sep 2006
    • 5

    #2
    Originally posted by spanky
    please help me,i'm given a task of writing a program,that ask the user to enter a sting,and then it output the number each letter is appearing,in the string.

    example of output:
    Enter a string:YOU ARE BEAUTIFUL
    A=2 appearance(s)
    B=1appearance(s )
    C=0 appearance(s)
    D=0 appearance(s)

    and so on up to letter 'Z'.

    Hi,
    You can directly compare the rach value of string using its ASCII code.
    i.e. first take a counter & increment it till string length != counter.
    Compare the each char in string with ASCII code(ie from 'A' to 'Z' ) that you want to search,if matches then increment a counter.

    Comment

    Working...