How to extract date in string into ints (month, day, year) using sscanf() in C++

1 Answer

0 votes
#include <iostream>

using std::cout;
using std::endl;

int main()
{
	int day, month, year;
	char date[] = "2/27/1966";
	
	sscanf(date, "%d%*c%d%*c%d", &month, &day, &year);

	cout << month << '-' << day << '-' << year << endl;

	return 0;
}


/*
run:

2-27-1966

*/

 



answered Jun 6, 2018 by avibootz
...