Need to convert a string format in C

Hi ,

I have a variable which stores the date in string format
example.. lets say char a='2-12-2016'
i want to convert the format to 2016/12/2

How to achieve this using C?


  • a char stores a single character, so char a='2-12-2016' isn't going to work. For your question, check into strchr.

    char s[] = "2-12-2016", *p;
    while((p = strchr(s, '-')) != NULL)
        *p = '//';

    don't forget to include string.h for strchr

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion