Thread: need help

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    72

    need help

    hi.. i was wondering is it possible to find out the following

    lets say i enter a string like => hello

    it should tell me that how many times a alphabet is used
    like if i enter "hello" it should give me the following
    h=1
    e=1
    l=2
    o=1

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Yes, the "count the characters" (AKA count occurence of each letter in a string) assignment. Search the forums, you'll find lots of hits.
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    72
    i did that, found not what i was looking for.. maybe u can write a program for the world "Hello" so i can understand it better? if so, ill be thankful

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    72
    anyone who can write a simple program for the above? thanks

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by salmansalman View Post
    anyone who can write a simple program for the above? thanks
    Yes, I'm sure I can... I even do not need to try it, to give you an answer
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by salmansalman View Post
    anyone who can write a simple program for the above? thanks
    The idea is to make an array of char's, 26 long, and set your a[] array elements all to zero.

    Now for each char in your word or sentence:

    a[char]++

    Welcome to distribution counting. At the end, you'll have a count of every char you've scanned:

    h = 1, e= 1, l = 2, o = 1.

    Very useful trick to remember.

  7. #7
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    But watch out for blanks, periods, exclamation and question marks (etc...), unless you reserve a spot for them in your array.
    Mainframe assembler programmer by trade. C coder when I can.

  8. #8
    Registered User
    Join Date
    Apr 2008
    Posts
    72
    well can I see a program? i dont understand the theory ;\

  9. #9
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    You are quite persistent. This is 4 pages of hits. One of them on the first page is a full program. http://cboard.cprogramming.com/showt...ing+characters
    Mainframe assembler programmer by trade. C coder when I can.

  10. #10
    Registered User
    Join Date
    Apr 2008
    Posts
    72
    rofl i never said how many times a charachter is entered :\\\\\\\\ blahhhhhhhhhhhh

    for example i put in the word => POWER <=

    it should tell me how much times each charachter is used.. like P is used once.. O iss used once as well etc so it should displayy

    p=1
    o=1
    w=1
    e=1
    r=1
    get it now? pplease wite a simple code here for any string from which i can get a idea

  11. #11
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    404
    You start the code, and someone else will critique and help you out.

  12. #12
    Registered User
    Join Date
    Apr 2008
    Posts
    72
    i have no idea what to put in the code, im asking u to write a simple program in C that will do it for the word hello or any other word so i can get the logic and syntax etc.. if u can help then help and if u cant help then just shut the fk up as im already ........ed off

    serious people who wants to help please do and whose people who wants to flame and say bull........ like "OMFG WE R SO ELITE HERE WE DUNT DO UR HOMEWORK" wtf, this is not any homework, im just trying to learn

    bye

  13. #13
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by salmansalman View Post
    serious people who wants to help please do and whose people who wants to flame and say bull........ like "OMFG WE R SO ELITE HERE WE DUNT DO UR HOMEWORK" wtf, this is not any homework, im just trying to learn

    bye
    Liar.

  14. #14
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    That's not at all the reason we don't do your homework. You are supposed to learn from the homework, and you won't learn anything by copying and pasting.

    You have been given an almost complete description of how you should implement it, and a link to another page.

    I mean, it's not like you can't solve it in just a couple of lines or so:
    Code:
    #include <stdio.h>
    #include <ctype.h>
    int main()
    {	int c[27]={ 0 },*q;char b[400],*p;
    	printf("Enter string:"); p = fgets(b,sizeof b,stdin);
    	for(;*p;p++) c[(isalpha(*p))?25-(tolower(*p)-97):26]++;
    	for(q=&c[25];q>=c;q--) { int x = (*q)?printf("%c: %d\n", 122-(q-c),*q):0;	} 
    	return 0; 
    }
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  15. #15
    Registered User
    Join Date
    Apr 2008
    Posts
    72
    lol time waster

Popular pages Recent additions subscribe to a feed