I am not sure what you're trying to do, but this is fishy:
while(6!=9)
{
/* ... */
}
/* ... more code ... */
6 will always not equal 9, so this is an infinite loop. There's no way to break out of the loop, and so nothing in the "more code" section will execute. This means that your printf
s won't execute, nor will your system
call. You need some way out of this loop.
To make the code easier to read (which should always be a top priority!), I would suggest just writing
while (true) {
...
}
to make it clearer that the loop is supposed to run until you explicitly break
from it.
Another note: this code
system("C:PROJECT X");
Is incorrect, because C++ will interpret P
as an escape character. To fix this, escape your slash:
system("C:\PROJECT X");
For another bug, look closely at this loop:
for(i=1;i<5;i++)
timetoken=strtok(''," ");
if(i==3)
{
strcpy(currtime,timetoken);
}
C++ is interpreting this as
for(i=1;i<5;i++) {
timetoken=strtok(''," ");
}
if(i==3)
{
strcpy(currtime,timetoken);
}
From here it's clearer that this won't work, since the if
statement is outside the loop. Consequently, i
is never 3. You probably meant
for(i=1;i<5;i++) {
timetoken=strtok(''," ");
if(i==3)
{
strcpy(currtime,timetoken);
}
}
Making the effort to clean up your code formatting (indentation, whitespace, etc.) will help prevent this sort of error. If you had declared i
as local to the for loop, then you probably would have spotted this earlier. For example, this code doesn't compile:
for(int i = 1; i < 5; i++) {
timetoken=strtok(''," ");
}
if(i==3) // i is not in scope
{
strcpy(currtime,timetoken);
}
As a general rule, defer declaring variables until you absolutely need them. It makes the code easier to read (variables in use tend to be close to the code using them) and less buggy (as shown above).
Hope this helps you get started!