program for enter your full name and then name is seprate according first,middle and last name

#include<stdio.h>

void seprate(char a[],char b[],char c[],char d[])

{

   static int i=0;

   int j=0,k=0,l=0,s=0;

      while(a[l]!='\0')

      {

          if((a[l]==' ' && a[l+1]!=' ')||l==strlen(a)-1)

          {

              s++;

          }

          l++;

      }

  while(1)

  {

      if(a[i]==32)

      {

          break;

      }

     b[i]=a[i];

     i++;

  }

  while(a[i]==32)

{

   i++;

}

if(s==3)

{

  while(1)

  {

       if(a[i]==32)

       {

           break;

       }

    c[j]=a[i];

    i++;

    j++;

  }

}

if(s==2||s==3)

{

while(a[i]==32)

  {

   i++;

  }

  while(1)

  {

    if(a[i]=='\0')

    {

        break;

    }

    d[k]=a[i];

    i++;

    k++;

  }

}

  return ;

}

void main()

{

 char a[50],b[50]=" ",c[50]=" ",d[50]=" ",o[50];

 printf("\n enter your full name");

 gets(a);

 strcpy(o,a);

 seprate(a,b,c,d);

 printf("\nyour full name is: %s",o);

 printf("\n your first name : %s",b);

 printf("\nyour  middle name: %s",c);

 printf("\nyour third name: %s",d);

}


Comments

Popular posts from this blog

BYTE STUFFING PROGRAM USING C

Rotate a matrix 270 degree AntiClockWise

Finding the length of connected cells of 1's (regions) in an matrix of 1's and 0's