Thread: String testing

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    3

    String testing

    Hello, im trying to design a function that takes in a string, and test it for having

    " The first 1/3 (rounding down) of the word's letters is repeated elsewhere in the word. e.g. abracadabra"

    I understand the logic of looping through the array, and finding matches, but have been un-able to create a working test that does the above task correctly.

    and help would be greatly appreciated.

    thanks
    nailz

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    What have you tried so far? Post some code. A pseudo-code is
    Code:
    find 1/3 of the word and store them in a string called KEY;
    for each letter in the word try to match one of the letters in KEY;
       If a letter matches, remove it from the KEY and procede;
    Loop, until there is no letter in KEY or in the word;

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    3
    Quote Originally Posted by C_ntua View Post
    What have you tried so far? Post some code. A pseudo-code is
    Code:
    find 1/3 of the word and store them in a string called KEY;
    for each letter in the word try to match one of the letters in KEY;
       If a letter matches, remove it from the KEY and procede;
    Loop, until there is no letter in KEY or in the word;
    I understand what you mean- i understand the basic logic that I need to do here, but actually writing it into code is proving to be a challenge



    this is my current stab at it, i apologize for the sloppy-ness.... it has gone under many revisions


    int Test4(char test4[])
    {
    char firstT[35];
    int wordLength = strlen(test4);
    int ndxPos, ndx2Pos, match, counter;
    int iteration = wordLength / 3;
    match = 0;
    counter = 0;

    for (ndxPos = 0; ndxPos < wordLength / 3; ndxPos++) {
    firstT[ndxPos] = test4[ndxPos];
    }
    for (ndxPos = iteration; ndxPos < strlen(test4); ndxPos++, counter++) {
    if (firstT[counter] == test4[iteration + counter]) {
    for (ndx2Pos = ndxPos; ndx2Pos < iteration + 3; ndx2Pos++) {
    if (firstT[counter] == test4[ndxPos + counter]) {
    match++;
    if (wordLength <= 5) {
    if (match - 1 == (wordLength + 2) / 3) {
    printf("%s is in category 4.\n", test4);
    return 1;
    }
    }
    else if (match == (wordLength + 2) / 3) {
    printf("%s is in category 4.\n", test4);
    return 1;
    }
    }
    counter++;
    }
    }
    }
    return 0;
    }

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    3
    bump

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  2. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  3. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  4. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  5. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM