| | |
Counting Alphabet Characters, Words, and String Length!
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2007
Posts: 3
Reputation:
Solved Threads: 0
I am suppose to create a program that counts the number of alphabets in string, words in a string and the lenght of the string and print them out! I have some code but I'm not sure how to get the string counted.
Can anyone please offer some help?
I pretty much have the basics I just need help counting the alphabets and finding out how to count the length and words that appear more than once!
Can anyone please offer some help?
I pretty much have the basics I just need help counting the alphabets and finding out how to count the length and words that appear more than once!
c Syntax (Toggle Plain Text)
#include<stdio.h> #include<ctype.h> #include<stdlib.h> #include<string.h> main() { char sentence[35]; char *letter[26] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j" "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w" "x", "y", "z"}; int num[26] = {0}; printf("\nEnter a sentence or phrase\n"); scanf("%s", &sentence); // loop to find alphabet characters and count each for(int j=1; j<=26; j++) { if(strchr(sentence, *letter[j]) != NULL) { ++num[*letter[j]]; printf("\'%c\' was found in \"%s\" %d times. \n",*letter[j], sentence, num[j]); } } }
Last edited by WaltP; May 2nd, 2007 at 3:13 am. Reason: Please learn to use CODE tags -- read the announcements at the top of the forum
•
•
•
•
Originally Posted by PeeJay
if(strchr(sentence, *letter[j]) != NULL) {
++num[*letter[j]];
printf("\'%c\' was found in \"%s\" %d times. \n",*letter[j], sentence, num[j]);
-->sometimes i wanna take my toaster in a bath<-- > Salem what are you talkin bout that doesn't matter its just code???Gosh
Because with correct indentation, I can figure out what code does about 10x quicker than a horrid unformatted mess like what you've posted.
So on seeing that most people who would help either
- drop your post to the bottom of their "to do" list, and if they run out of time, you lose.
- simply forget about trying to help you as you can't even be bothered with the simple niceties, so you lose again.
But rather than fixing the problem, you instead want to bitch about my attempt to get you to read the rules and improve your post quality.
Nah, forget it, you simply aren't worth the effort anymore.
Because with correct indentation, I can figure out what code does about 10x quicker than a horrid unformatted mess like what you've posted.
So on seeing that most people who would help either
- drop your post to the bottom of their "to do" list, and if they run out of time, you lose.
- simply forget about trying to help you as you can't even be bothered with the simple niceties, so you lose again.
But rather than fixing the problem, you instead want to bitch about my attempt to get you to read the rules and improve your post quality.
Nah, forget it, you simply aren't worth the effort anymore.
•
•
Join Date: Apr 2007
Posts: 3
Reputation:
Solved Threads: 0
Salem thanks for the advice. However, I would suggest you use better diction when talking to people. Your point would come across a little better and could be more effective if you didn't come across as such a"know it all" so to speak! I am new to this discussion community as you've probably already seen but I'm not a dummy so don't talk to me like one! Thanks again for the advice and watch the diction!
Last edited by PeeJay; May 2nd, 2007 at 11:42 am.
>I am new to this discussion community as you've probably already seen
>but I'm not a dummy so don't talk to me like one!
Whether you're new or not is irrelevant. You've shown a lack of concern for proper formatting despite being told in detail the merits of it. I'm sorry, but that makes you look like a "dummy", and when you look like a dummy, you'll be treated like one.
>Your point would come across a little better and could be more effective
>if you didn't come across as such a"know it all" so to speak!
The message is there. If you don't care to see it and instead focus on imagined insults, that's not Salem's problem. Of course, even if you watch your diction, there will still be misunderstandings. For example, your little suggestion and choice of words strikes me as haughty. So maybe you should watch your diction.
>but I'm not a dummy so don't talk to me like one!
Whether you're new or not is irrelevant. You've shown a lack of concern for proper formatting despite being told in detail the merits of it. I'm sorry, but that makes you look like a "dummy", and when you look like a dummy, you'll be treated like one.
>Your point would come across a little better and could be more effective
>if you didn't come across as such a"know it all" so to speak!
The message is there. If you don't care to see it and instead focus on imagined insults, that's not Salem's problem. Of course, even if you watch your diction, there will still be misunderstandings. For example, your little suggestion and choice of words strikes me as haughty. So maybe you should watch your diction.
New members chased away this month: 4
•
•
•
•
Salem thanks for the advice. However, I would suggest you use better diction when talking to people. Your point would come across a little better and could be more effective if you didn't come across as such a"know it all" so to speak! I am new to this discussion community as you've probably already seen but I'm not a dummy so don't talk to me like one! Thanks again for the advice and watch the diction!
c Syntax (Toggle Plain Text)
char *letter[26] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j" "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w" "x", "y", "z"}; [...] for(int j=1; j<=26; j++) {
Regards Niek
[edit]
Don't take Narue's post to serious, she has a.. euhm.. 'special' way of putting things
Last edited by niek_e; May 2nd, 2007 at 11:55 am.
![]() |
Similar Threads
Other Threads in the C Forum
- Previous Thread: dealing with object files
- Next Thread: Problems when trying to store things as a string that has quotes.
Views: 5016 | Replies: 8
| Thread Tools | Search this Thread |
Tag cloud for C
* adobe api append array arrays bash binarysearch char character cm copyanyfile copypdffile createcopyoffile createprocess() csyntax directory drawing dynamic executable execv feet fgets file floatingpointvalidation fork frequency function getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux highest homework i/o ide infiniteloop initialization input interest intmain() iso keyboard kilometer lazy license linked linkedlist linux list lowest matrix meter microsoft mqqueue multi mysql oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scheduling segmentationfault send single socketprogramming spoonfeeding stack standard strchr string student suggestions system test testautomation unix urboc user whythiscodecausesegmentationfault win32api windows.h






