printf parts from a string

This is a discussion on printf parts from a string within the C Programming forums, part of the General Programming Boards category; How can I print the last parts of a string? For example I have AAA_BBB and I want to print ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    167

    printf parts from a string

    How can I print the last parts of a string? For example I have AAA_BBB and I want to print just _BBB. Can this be done without removing the first chars? Something like printf("%.4s"...); Something like this i'm looking for

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, as long as you know where in the string you want to start printing something like this will work:

    Code:
        // assume pos is where we start and len is the length of what needs displaying:
        char *s1 = &str[pos];
        printf("%*s", len, s1);
    --
    Mats

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    167
    yes I understand smart aproach.. dumb me

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, 05:30 PM
  2. RicBot
    By John_ in forum C++ Programming
    Replies: 8
    Last Post: 06-13-2006, 07:52 PM
  3. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 10:19 AM
  4. Another overloading "<<" problem
    By alphaoide in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2003, 11:32 AM
  5. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21