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++;
}
commented: you should tell him how to do it not to do it for him , it's his homework not yours +0

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

Lol to return information to main. So you can display.

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';
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.