Thread: switch case....

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    51

    switch case....

    say i wanted to store a phrase in a string, tokenize it , and run the words through a counter to see how freqently the numbers of the letters in the words appear.


    for intstance

    say i entered

    "today is a good day to die!"

    i want it to say

    # of letters in word freqency of words
    1 1
    2 2
    3 2
    4 1
    5 1

    i have some code to show what ive been "trying " to do

    Code:
    
    
    
    char string1[]="the mathamatics curriculum guidelines envision that all students.";
    
    char *tokenPtr;
    tokenPtr = strtok (string1, " ");
    
    
    while (string1 !='\0'){
       
    tokenPtr = strtok(NULL, " ");
    int x = strlen(string1) // i know that only does one word, but i dont know how to make it do the whole phrase :(	
    switch(x){
    case 1:
    	ctr1++;
        break;
    case 2:
    	ctr2++;
        break;
    case 3:
    	ctr3++;
        break;
    case 4:
    	ctr4++;
        break;
    case 5:
    	ctr5++;
        break;

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    To answer you question:

    Example
    Code:
    tokenPtr = strtok(NULL, " ");
    while(tokenPtr) {
      // you code here
      tokenPtr = strtok(NULL, " ");
    }
    But I do have to say that you may have some trouble getting your program to do what you are describing. Since I this is obviously not the entire source code for your program I won't say too much now. But I hope that gets you on track.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can I make this code more elegant?
    By ejohns85 in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2009, 08:55 AM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  3. Replies: 27
    Last Post: 10-11-2006, 04:27 AM
  4. Problems with switch()
    By duvernais28 in forum C Programming
    Replies: 13
    Last Post: 01-28-2005, 10:42 AM
  5. rand()
    By serious in forum C Programming
    Replies: 8
    Last Post: 02-15-2002, 02:07 AM