CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: little help

  1. #1
    Join Date
    Jun 2002
    Posts
    59

    little help

    I having little problem adding a "-" to 20 charaters.. for example,
    0K4CJQ6K7301T1159251

    i was trying separate the long string by 4 and after every 4 charaters would add "-"

    like this 0K4C-JQ6K-7301-T115-9251

    how would i do this? i know looping is involve but dont know how to put together..



    thank you for your time

  2. #2
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: little help

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char *argv[])
    {
        const char *szKey = "0K4CJQ6K7301T1159251";
        char szEnd[256] = "";
        int i = 0;
        int iLen = strlen(szKey);
        
        printf("Key before processing: %s\n", szKey);
        
        for ( i = 0; i < iLen; i += 4 )
        {
            if ( i )
            {
                strcat(szEnd, "-");
            }
            strncat(szEnd, (szKey+i), 4);
        }
        printf("Key after processing: %s\n", szEnd);
        
        system("PAUSE");
        return 0;
    }
    This was 5 minuite work. Hope this helps.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  3. #3
    Join Date
    Jun 2002
    Posts
    59

    Re: little help

    whoa!

    thanks for the codes.

  4. #4
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: little help

    Quote Originally Posted by mc0282
    whoa!

    thanks for the codes.
    You are very welcome.

    / I hope you do not need it for an illegal keygen
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured