I have a problem, I need to store my printf screen into a variable and output it back to the user. I am super new to c. So any help would be greatly appreciated.
My code is below:
Code:
#include <stdio.h>
#include <time.h> /* time_t, struct tm, time, gmtime */
int main (){
//Create time structure
time_t temp = time(NULL);
struct tm *tick_time = localtime(&temp);
//Store current day# in year
static char s_day_text[] = "DAY 000/";
strftime(s_day_text, sizeof(s_day_text), "DAY %j/", tick_time);
//Store current year in variable
static char s_year[] = "0000";
strftime(s_year, sizeof(s_year), "%y", tick_time);
int year = atoi(s_year);
int total_days=000;
//Determine if current year is a leap year
if(year%4 == 0 && year%100 != 0 || year%400 == 0){
total_days = 366; //Year is a leap year
}else{
total_days = 365; //Year is not a leap year
}
//Need this print out to be stored in variable
printf("%s%d\n" ,s_day_text ,total_days);
//My poor attempts to store a complete printf into a variable
/*strcat(s_day_text,total_days);*/
char *buffer[21];
snprintf(buffer, "%s%d\n" ,s_day_text ,total_days);
printf(buffer);
return 0;
}