Click to See Complete Forum and Search --> : little help


mc0282
January 22nd, 2005, 11:04 AM
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 :)

NoHero
January 23rd, 2005, 10:02 AM
#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.

mc0282
January 23rd, 2005, 11:53 AM
whoa!

thanks for the codes.

NoHero
January 24th, 2005, 04:12 AM
whoa!

thanks for the codes.

You are very welcome.

/ I hope you do not need it for an illegal keygen :rolleyes: