Link to home
Start Free TrialLog in
Avatar of edvinson
edvinsonFlag for United States of America

asked on

Building and appending string, my code is LONG

I am simply trying to build a string that displays the first 4 numbers of Hard Drive serial number, a hyphen,  and append the first four letters of today's day name.

Example:

2190-Wedn


The code below WORKS but I think I am taking the long way. Can anyone help me refactor this code a bit?

Thanks

 //-----------------------------------------------------------------
                       // Check Number Three: First four of HD Serial Number


                        LPCTSTR szHD = "C:\\"; // A pointer to a constant null-terminated string
                        UCHAR szFileSys[255],szVolNameBuff[255];
                        DWORD dwSerial,dwMFL,dwSysFlags;
                        BOOL bSuccess;

                        bSuccess = GetVolumeInformation(szHD,(LPTSTR)szVolNameBuff,
                                         255,&dwSerial, &dwMFL,&dwSysFlags,
                                         (LPTSTR)szFileSys,255);

                        // Convert to Character, Move to szHdSerial
                        wsprintf(szHdSerial,"%lu", dwSerial);


                        // Loop through, get first 4 chars
                        for(int ii=0 ; ii<4 ; ii++)
                        {
                            finalCombination[ii] = szHdSerial[ii];
                        }

                        std::string fC;
                        fC = finalCombination;
                        std::string hyphen = "-";
                        fC.append(hyphen);
                        strcpy (finalCombination, fC.c_str());

                        //MessageBox(NULL,finalCombination,"a",NULL);

                       //-----------------------------------------------------------------
                       // Check Number Four: Build String to use Cypher against
                        time_t rawtime;
                          struct tm * timeinfo;
                          char buffer [80];

                          time ( &rawtime );
                          timeinfo = localtime ( &rawtime );
                          strftime (buffer,80,"%A",timeinfo);
                          // buffer now contains "Wednesday"
                          for(int ii=0 ; ii<4 ; ii++)
                          {
                            finalCombination[ii+5] = buffer[ii];
                          }
                            fC = finalCombination;


                          strcpy (finalCombination, fC.c_str());

                            //MessageBox(NULL,finalCombination,"a",NULL);
                            // Now 2190-Wedn

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial