Thread: Need help with string

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    1

    Need help with string

    Hi, I am quite new to C. I am kind of stuck at last part of my project which require me to list the number of locations the this sub string found

    User need to input secret code: eg. aabfd
    Given string: "vbfdaabfhjkhhgfjjuaabuyytttyuauuuyyu

    How wud u be able to detect the occurrence of this partial secret code?

    output should read as "Partial secret code occur at 5,d 19,fd,

    Ur help is very much appreciated. Thank u in advance

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Simply use the same logic for the program, that you would use for solving this, with paper and pencil.


    This is the idea - this is NOT ready to run code.

    Code:
    len = strlen(string);
    for(i=0,j=0;i<len;i++) {
      if(string[i] == code[j]) { //found the first letter of the code
        j=i;
        while(a[j] == code[j])   { //while the string has matching letters
          ++j;
           //print it or whatever you want to process matches
        }
        //does j match the length of the code string?
        //if so, you have a full match, else a partial match  
      }
    }
    Study your problem, and you'll get it. You'll want to include string.h for most work with strings, of course.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM