C++ Debug assertion failed

Filip 831 Reputation points
2021-04-10T12:31:29.907+00:00

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;  
}  
Developer technologies | C++
Developer technologies | C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Igor Tandetnik 1,116 Reputation points
    2021-04-10T13:27:15.92+00:00

    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.

    2 people found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.