Thread: Slicing's string concept.

  1. #1
    Banned
    Join Date
    Apr 2015
    Posts
    596

    Slicing's string concept.

    Hi everybody!, I just was wondering how would I print a specific string slice like what we used to do in python language, which there we were doing string[0:4] that's leading to print from index 0 to 3..etc.
    How about C programming? isn't there a specific algorithm or function to do string slicing?

    thanks beforehand for your cooperating.

  2. #2
    Registered User
    Join Date
    Jun 2009
    Posts
    120
    Code:
    #include <stdio.h>
    
    void print_slice(const char *str, unsigned int begin, unsigned int end)
    {
        printf("%.*s", end - begin, str + begin);
    }

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    It's against forum rules to give out complete solutions. Please don't do it. The OP will learn nothing from this, and will now just copy and paste the code, not caring how it actually works.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  4. #4
    Banned
    Join Date
    Apr 2015
    Posts
    596
    Firstly, thanks for the answer.
    secondly regarding to dark, I really didn't tell in my question that I'm heading for complete solutions, I just asked if there's a pre-quick-function in C (commands) that's used for what I've asked upper.

    And I still a lil confused, can u give me an example of the code that you have written above?

    thanks.
    Last edited by RyanC; 04-28-2015 at 07:02 AM.

  5. #5
    Banned
    Join Date
    Apr 2015
    Posts
    596
    ah thanks, got the idea.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Slicing problem with inherited classes.
    By Swerve in forum C++ Programming
    Replies: 6
    Last Post: 10-20-2009, 02:29 PM
  2. Polymorphism - Slicing?
    By Tonto in forum C++ Programming
    Replies: 11
    Last Post: 07-24-2006, 12:07 PM
  3. Slicing an image
    By InvariantLoop in forum Tech Board
    Replies: 1
    Last Post: 04-30-2004, 01:13 AM
  4. Concept help
    By Mithoric in forum Windows Programming
    Replies: 13
    Last Post: 04-18-2004, 03:05 PM
  5. Slicing
    By ygfperson in forum C++ Programming
    Replies: 4
    Last Post: 05-03-2003, 07:18 PM