Thread: printf parts from a string

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