Question d’entretien chez Roblox

Write "cd" functionality for a path container provided.

Réponses aux questions d'entretien

Utilisateur anonyme

13 juil. 2017

Basically taking the new path, splitting it, finding out if it started with "/" to change the root, then walking thru the items and either appending it to a new path list or removing the last item in the path list if the item is "...".

Utilisateur anonyme

3 févr. 2020

// This solution is intended for use on Windows platforms. // If paths may be provided in relative format, use PathCchCanonicalize to convert to absolute. // If unsure, use PathIsRelative to verify and convert as needed. // If paths may be provided with file specs included, use PathIsFileSpec to identify, // and then PathCchRemoveFileSpec to remove it. TCHAR tszPathSource[] = TEXT("c:\\x\\abc\\123"); TCHAR tszPathTarget[] = TEXT("c:\\x\\abc\\456"); LPTSTR lptszPathSource = &tszPathSource[0]; LPTSTR lptszPathTarget = &tszPathTarget[0]; // Verify that the source and target exist before going forward. // The source may not seem as important, but if it's invalid... it's likely a bug. if (PathIsDirectory(lptszPathSource) && PathIsDirectory(lptszPathTarget)) { // Advance the pointers to the point that the two paths converge. while (*lptszPathSource && *lptszPathTarget) { if (*lptszPathSource != *lptszPathTarget) { // When they no longer converge, assign the remaining parts of the source to the target. while (*lptszPathSource) { *lptszPathTarget = *lptszPathSource; lptszPathSource++; lptszPathTarget++; } // Change to the target path. SetCurrentDirectory(tszPathTarget); break; } lptszPathSource++; lptszPathTarget++; } }