Thread: Words

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    3
    Rep Power
    0

    Words


    I wanted to write a program

    " All the words with Minimum four letter word and maximum nine letter word with no letter is repeated more than twice in word. "
    or
    atleast All the words with minimum four letter word and maximum nine letter word possible.

    Any suggestions or help.
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,413
    Rep Power
    1871
    What is your definition of "word"?

    Is "aaaa" a word, or do you have a dictionary (or word list) containing only valid words?

    What you need to do first is get a pencil and some paper, and figure out how to solve the problem on paper.

    That is, you need to understand the process which say gets you from "aaaa" to "aaab" up to "aaaz" and then onto "aaba".

    Until you understand the mechanics of how it works on paper, you're never going to be able to write the code to do it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    3
    Rep Power
    0
    You are right. I am not asking about the dictionary words. words could be any with or without any meaning.

    even AAbb is a word. and I want output of all the words that can exist with minimum four letters and containing maximum nine letters.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    3
    Rep Power
    0
    # include<stdio.h>

    int main()
    {
    char array[100],c;
    int i, word=0,count=0;
    char *p;

    for(i=0;;i++)
    {
    p=&array[i];
    scanf("%c",&c);
    count++;
    if(c=='\n')
    {
    *p='\0';
    break;
    }
    *p=c;
    }

    for(p=&array[0];*p;p++)
    {
    if(((*p<='z' && *p>='a') || (*p<='Z' && *p>='A')) && !((*(p+1)<='z' && *(p+1)>='a') ||(*(p+1)<='Z' && *(p+1)>='A')))
    {
    word++;
    }
    }


    printf("%d\n",word);
    printf("%d\n",count);

    return 0;
    }

    Erorrs ?
  8. #5
  9. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,413
    Rep Power
    1871
    I assume you have a compiler, and are able to compile and run the code.

    Rather than just dump the code (you also forgot the [code][/code] tags, making it unreadable), you should test it yourself.

    Now if you had posted the code in code tags, and explained (for example) that it manages to print "aaaa" to "aaaz" but then it goes back to "aaaa" and not the next expected value of"aaba". You see, that would be an actual bug report we could investigate.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper

IMN logo majestic logo threadwatch logo seochat tools logo