I'm using this command-line parameters in my executable:
myprogram.exe c:\programmi\driver.exe c:\programmi\seti.exe
My code looks for the parameter, it is cut in 2 pieces divided by the "space" and I want to save the 2 pieces.. then every piece is cut in smaller pieces divided by "\" untill I get the executable name.. so at the end I want to print the 2 path i gave as parameter and the name of the 2 exe found in the path given :
Code:
#include <stdio.h>
#include <string.h>
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char * lpCmdLine, int nCmdShow)
{
char separatoriexe[] = "\\";
char separatori[] = " ";
char *seti;
char *tempseti;
char *tempdriver;
char *setiexe;
char *driver;
char *driverexe;
driver = strtok( lpCmdLine, separatori );
seti = strtok( NULL, separatori );
tempseti = strtok( seti, separatoriexe );
while( tempseti != NULL )
{
setiexe = tempseti;
tempseti = strtok( NULL, separatoriexe );
}
tempdriver = strtok( driver, separatoriexe );
while( tempdriver != NULL )
{
driverexe = tempdriver;
tempdriver = strtok( NULL, separatoriexe );
}
printf( "Driver: %s\n", driver );
printf( "Seti: %s\n", seti );
printf( "Exe di Seti: %s\n", setiexe );
printf( "Exe di Driver: %s\n", driverexe );
system("PAUSE");
return 0;
}
But it seems that the strtok modify the string after the manipulation...what should I do to conserve the strings (I need them in all the code so I HAVE to conserve them)??
I get this wrong output:
Driver: c:
Seti: c:
Exe di Seti: seti.exe
Exe di Driver: driver.exe
Instead this one that is right:
Driver: c:\programmi\driver\driver.exe
Seti: c:\programmi\driver\seti.exe
Exe di Seti: seti.exe
Exe di Driver: driver.exe
help please