question

Filip-2434 avatar image
0 Votes"
Filip-2434 asked IgorTandetnik-1300 answered

C++ Debug assertion failed

Hello.
I had an error.
How can i fixed it?
Thanks for answare.
86445-a.png


Code:

 #include<iostream>
 #include<stdio.h>
 #include<stdlib.h>
 using namespace std;
    
 //function to set date and time
 void setDateTime(int date, int month, int year, int hour, int min, int sec)
 {
     //buffer to format command
     unsigned char buff[32] = { 0 };
     //formatting command with the given parameters
     //sprintf((char*)buff, (const char*)"date -s \"%02d/%02d/%04d %02d:%02d:%02d\"", month, date, year, hour, min, sec);
     //execute formatted command using system()
     system((const char*)buff);
 }
    
 int main()
 {
        
     //calling function by passing date and time
     setDateTime(25, 6, 2017, 10, 10, 10);
     cout << endl;
     return 0;
 }







c++
a.png (165.0 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

IgorTandetnik-1300 avatar image
2 Votes"
IgorTandetnik-1300 answered

You are passing an empty string to system. The implementation specifically asserts that the parameter not be an empty string.

You fix it by passing a valid command, and not an empty string.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.