HI Everyone !
Do anyone know how to split string ? Especially this one .
Do anyone know funtion "__DATE__" , it show month/date/year. you know ,it is string so i want to separate it because i need month to make condition.

here is the logic.....

split(char *original, char * split1, char * split2)
{
  int i = 0;
  int j = 0;
  int flag = 0;

  while (original[i] != '\0')
  {
     if (flag == 0)
     {
        if (original[i] == '-')
        {
           flag = 1;
           split1[i] = '\0';
        }
        else
        {
           split1[i] = original[i];
        }
     }
     else
     {
        split[j++] = original[i];
     }
     i++;
}

Edited 5 Years Ago by Nick Evan: Added [CODE] tags!

Comments
you should tell him how to do it not to do it for him , it's his homework not yours

hi vivek.kumar
it seem like i don't understand your logic. why we need three parameter ?

vivek.kumar: your code is good, but you forgot the void before the function definition and you forgot the '\0' for split2. And I would add a parameter for the delimiter that you use to split the strings.

void split(char *original, char * split1, char * split2, char delim)
{
  int i = 0;
  int j = 0;
  int flag = 0;
 
  while (original[i] != '\0')
  {
     if (flag == 0)
     {
        if (original[i] == delim)
        {
           flag = 1;
           split1[i] = '\0';
        }
        else
        {
           split1[i] = original[i];
        }
     }
     else
     {
        split2[j++] = original[i];
     }
     i++;
  }
  
  if (flag == 0) split1[i] = '\0';
  split2[j] = '\0';
}

Edited 5 Years Ago by chrjs: n/a

This article has been dead for over six months. Start a new discussion instead.