Click to See Complete Forum and Search --> : How to do with a group of chars? Thanks.


xmasry
April 27th, 2005, 09:53 PM
I want to do with a group of chars, like

char oldchar[30]="00:00:00.04,00:00:00.14 " changed to
char newchar[30]="00:00:00,040 --> 00:00:00,140".

maybe, it is easier when first it is changed to CString,then it can use the function :
substr(),+ and other things?

Would you have any suggestion?

cilu
April 29th, 2005, 12:09 PM
char oldchar[30]="00:00:00.04,00:00:00.14 " changed to
char newchar[30]="00:00:00,040 --> 00:00:00,140".

If this this format is fixed, that you can do this (note this code isn't tested)

char oldchar[30]="00:00:00.04,00:00:00.14";
char newchar[30];
int oldpos = 0;
int newpos = 0;

strcpy(newchar+newpos, oldchar+oldpos, 8); // copy 00::00:00
newpos += 8;
oldpos += 8;

newchar[newpos] = ','; // replace . with ,
newpos++;
oldpos++;

strcpy(newchar+newpos, oldchar+oldpos, 2); // copy 04
oldpos += 2;
newpos +=2;

newchar[newpos++] = '0'; // add a 0 at the end

oldpos++; // skip the comma

char del [] = " --> ";
strcpy(newchar+newpos, del, strlen(del)); // copy the -->
newpos += strlen(del);

strcpy(newchar+newpos, oldchar+oldpos, 8); // copy 00:00:00 part
newpos += 8;
oldpos += 8;

newchar[newpos] = ','; // replace . with ,
newpos++;
oldpos++;

strcpy(newchar+newpos, oldchar+oldpos, 2); // copy 04
oldpos += 2;
newpos +=2;

newchar[newpos++] = '0'; // add a 0 at the end

newchar[newpos++] = 0; // null terminating char