Thread: Struck substring w/o strstr()

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    3

    Struck substring w/o strstr()

    Hello! I have o proble in c

    i have 3 stings on a struct (given from keyboard), and i want to find if a new string (from keyboard too) is a substring of the above 3 strings and the position tha it fount, without using strstr() function.

    the struct have two values, the string and the string lenght

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Hmm I understand the problem.. What is your code so far?

    Also welcome to the forum.

    I suppose you have already read the rules of this forum and the policy for the hw.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You could
    a) write the code using strstr() to make sure everything works
    b) write your own version of say my_strstr() to replace the library strstr() and make sure it still works.
    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. #4
    Registered User
    Join Date
    Feb 2013
    Posts
    3
    Sorry for the delay!

    Ive made something like that

    Code:
    for (k=0;k<size;k++){
    for (j = 0; j <= (st[i].length - lenght2); ++j){
          for (i = 0; i < lenght2 && st[i].string[j] == input[i + j]; ++i);
     if (i >=  lenght2) {printf("\nMatch found at\n\n->[%d]\n->[%s]\n",j,input+j);} 
       }
    
    st[i].string[j] = the struct's strings
    st[i].length =  the length of struct string
    input = the substring
    lenght2 = the substrings lenght
    size = the st[i].string[j] size

  5. #5
    Registered User
    Join Date
    Feb 2013
    Posts
    3
    I fount it, so dont bother. Thanx anyway!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Struck at number pyramid !!
    By rajarshi in forum C Programming
    Replies: 5
    Last Post: 11-04-2011, 01:19 AM
  2. substring in C
    By -EquinoX- in forum C Programming
    Replies: 2
    Last Post: 04-18-2008, 01:39 PM
  3. Replies: 11
    Last Post: 12-11-2005, 11:50 PM
  4. Getting a substring help plz
    By joshua in forum C Programming
    Replies: 3
    Last Post: 11-01-2005, 06:11 PM
  5. How to substring ?
    By appsforum in forum C Programming
    Replies: 1
    Last Post: 09-10-2001, 03:22 PM