mano M wrote: > Hi , > > i have string as follows. > > char dest[11]; > char buffer[9]; > strcpy(buffer,"20071201"); > > /* I need to convert it into YYYY-MM-DD format. > I am trying to use strcat and strncpy . But it looks liitle complex for > getting last month and day. Or do I miss any basic functions? > Actually I do not want to convert to integer to parse it > */ > What would be the best solution for this convertion. I am expecting out put > as > 2007-12-01 > > Thanks, > Mano
Paul's suggestion works and is probably more reliable (although I'm not sure why he threw in a newline in the sprintf() statement). Since you have fixed input and output (check all user input!), an alternate route might be to do: memcpy(dest, buffer, 4); dest[4] = '-'; memcpy(dest + 5, buffer + 4, 2); dest[7] = '-'; memcpy(dest + 8, buffer + 6, 2); dest[10] = '\0'; That doesn't convert to numbers, is a lot harder to read, and doesn't have validation of any sort, but it also doesn't convert anything into integers as per your request. -- Thomas Hruska CubicleSoft President Ph: 517-803-4197 *NEW* MyTaskFocus 1.1 Get on task. Stay on task. http://www.CubicleSoft.com/MyTaskFocus/