Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3788162
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:57:17+00:00 2026-05-19T11:57:17+00:00

Say I want to print using printf(format, YYYYMMDD); How would format look if I

  • 0

Say I want to print using

printf(format, "YYYYMMDD");

How would format look if I wanted my output to look like “MM-DD-YYYY”?

Thanks.

Let me add my full code so there’s no confusion.

I have a sruct defined as

typedef struct{
       char     *dt;    
       float     op, hi, lo, cl, vl; 
}STOCKDATA; 

Then call a function:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>

#include "../include/struct.h"
#include "../include/function.h"
#include "../include/utility.h"

#define linemax 514 
void  stockData(char *ticker)     
{
     extern STOCKDATA *stockdata;
     extern int nrows;

     //count number of lines in file..............................
       char *filename;
       mkstring("../data/", ticker, filename);
       nrows=linesInFile(filename);

     //allocate stockdata.........................................

       stockdata=malloc_stockdata(0,nrows-1);

     //open file to read into stockdata...........................
     FILE *fp;
     fp = fopen(filename, "r");   
     if(fp==NULL) 
     {
         printf("%s%s\n", "Can't open data file ", filename);
         exit(1);
     }

     char delimiters[] = " ,";
     char line[linemax];

     char *tmp;

     fgets(line, linemax, fp);               //skip header 

     int  count=0;                           //count number of lines
     while( fgets(line, linemax, fp) !=NULL)
     {
          tmp=strtok(line, delimiters);      //ticker (skipped)

          stockdata[count].dt= strtok(NULL, delimiters);         //date
//printf("%s\n", stockdata[count].dt);
          stockdata[count].op=atof(strtok(NULL, delimiters));   //open
          stockdata[count].hi=atof(strtok(NULL, delimiters));   //high
          stockdata[count].lo=atof(strtok(NULL, delimiters));   //low
          stockdata[count].cl=atof(strtok(NULL, delimiters));   //close
          stockdata[count].vl=atof(strtok(NULL, delimiters));   //volume

          count++;
     }

     fclose(fp);
}

Then call the function:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#include "../include/struct.h"
#include "../include/function.h"
#include "../include/utility.h"


#define cutoff 10
void writeData(char *ticker)
{

   extern STOCKDATA  *stockdata;
   extern int nrows;

  //open output file........................................
   char *filename;
   mkstring("../output/", ticker, filename);

    FILE *fp;
    fp = fopen(filename, "w");
    if(fp==NULL)
    {
         printf("%s%s\n", "Can't open data file ", filename);
         exit(1);
    }


  int k;
  char *format="%-15s%-10.2f%-10.2f%-10.2f%-10.2f%-10.0f\n";
  for (k=nrows-cutoff; k<nrows; k++)
  {
   fprintf(fp, format, stockdata[k].dt,
                       stockdata[k].op,
                       stockdata[k].hi,
                       stockdata[k].lo,
                       stockdata[k].cl,
                       stockdata[k].vl );

  }

  fclose(fp);

}

Now, where I define ‘format’ in the last function call, I’m trying to make it print stockdata[k].dt in a MM-DD-YYYY format. The string in the data file is in YYYYMMDD.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T11:57:17+00:00Added an answer on May 19, 2026 at 11:57 am

    You want to look into strptime and strftime. First, you need to parse the date you have (using strptime) like so:

    struct tm timeStruct;
    strptime(dateString, "%Y%m%d", &timeStruct);
    

    Then convert it to the new format using strftime:

    strftime(outputString, sizeof(outputString), "%m-%d-%Y", &timeStruct);
    

    Now outputString contains the date in the format you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I want to do something like this void my_printf(char *fmt,...) { char
Let's say I want to print the first 3 items of a list. So
Say if i want to print out my integer stored inside a array ,
Say I have the code: print(>>> ) command = gets What I want to
Say I want to write a function like this: int get_some_int(string index) { ...perform
First, let me say that I am aware of the cons of using recursive
I'm trying to print a boost::posix_time::ptime in the format of YYYY-MM-DD hh:mm:ss.fff where the
I want to convert 1/2 in python so that when i say print x
Lets say I want to use Box2D javascript to simply print the coordinates of
I want to pause the timer thread....or i can say want to put it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.