Thread: printing the longest suffix after a pattern

  1. #1
    Registered User
    Join Date
    Apr 2021

    printing the longest suffix after a pattern


    I'm new to C language and I'm struggling quite a bit.

    I'm trying to play around with patterns. So far, I managed to print out the amount of substrings between a certain pattern, for example if my input is "hi", my output would be 1.

    When my input is"hi there", it would be 2. And when my input is "hi!there", it would also be 2. I would have 3 as an output when my input is this: "hi__there__girl"

    Now, I want to change it that it prints the last whole substring after a pattern.
    So if my input is "hi::there", I want my output to be "there" (instead of the number 2), or when my input is "hi__there__girl" I want the output to be "girl".

    Input always is just one long series of letters, numbers and patterns.

    I don't know how to do that - I manage only to count the substrings between the patterns, but I don't know how to find and print the last suffix after a pattern.

    Could anyone help me please?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    What is a "pattern"?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2021
    Quote Originally Posted by laserlight View Post
    What is a "pattern"?

    For example, "__" (two underlines), " " (a whitespace), "::" (two double points) are a pattern that the code is supposed to find.
    Those patterns determine where a new substring begins.

    "he::llo" has two substrings, one being 2 characters long, one being 3 characters long. The pattern "::" divides them.

    My current code finds that the input "he::llo" is divided by one "::"-pattern and prints "2", because the :: seperates the whole String into two substrings.

    But now I don't want the output to be a number. I want it to print out the last substring, in my example, I want "llo" printed out.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing a pattern to the screen
    By PhantomJoe in forum C Programming
    Replies: 17
    Last Post: 10-22-2017, 10:14 AM
  2. Pattern Printing
    By sunny` in forum C Programming
    Replies: 2
    Last Post: 03-18-2012, 09:11 PM
  3. need help printing this pattern
    By Blimpy325 in forum C Programming
    Replies: 4
    Last Post: 03-04-2006, 06:40 AM
  4. Printing a pattern correctly???
    By Basia in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 04:34 PM
  5. Printing a Pattern of Stars
    By ProgrammingDlux in forum C++ Programming
    Replies: 13
    Last Post: 03-01-2002, 08:38 AM

Tags for this Thread