How to parse formatted string in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>

int main(void) 
{
    char date[]="date : 08-05-2017";
    char s[10];
    int day, month, year;
    
    sscanf(date," %s : %2d-%2d-%4d", s, &day, &month, &year);
    
    printf("%s : %02d-%02d-%4d\n",s, day, month, year);
    
    return 0;
}
   
/*
run:

date : 08-05-2017

*/

 



answered Aug 5, 2017 by avibootz

Related questions

1 answer 200 views
3 answers 322 views
1 answer 226 views
1 answer 122 views
1 answer 92 views
92 views asked May 8, 2022 by avibootz
1 answer 199 views
1 answer 213 views
...