Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  rev
Language: C/C++
Code:
#include    <stdio.h>
#include     <stdlib.h>
#include     <math.h>
#include     <string.h>
#include     <malloc.h>


#define MAX_LINE_LEN 1000
#define MAX_WORD_LEN 256

int main()
{
     char InLine          [MAX_LINE_LEN];
     char InLineArr  [MAX_LINE_LEN];
     char OutLineArr [MAX_LINE_LEN];
     char InWordArr  [MAX_WORD_LEN];
     char OutWordArr [MAX_WORD_LEN];
     int j =0;
     memset(InLine,'\0',sizeof(InLine));
     memset(InLineArr,'\0',sizeof(InLineArr));
     memset(OutLineArr,'\0',sizeof(OutLineArr));
     memset(InWordArr,'\0',sizeof(InWordArr));
     memset(OutWordArr,'\0',sizeof(OutWordArr));
     
     printf("Enter input line \n");
     scanf("%s", &InLine);

     for (int i=0,i<=strlen(InLine),i++)
     {
          if (InLine[i] == ' ' || i == strlen(InLine))
          {
                    if (InLine[i] == ' ')
                    {
                         strcat(" ",OutWordArr);
                    }
                    strcat(OutWordArr,OutLineArr);
                    memcpy(OutLineArr,OutWordArr);
                    j = 0;
                    memset(OutWordArr,'\0',sizeof(OutWordArr));
          }
          else 
          {
               OutWordArr[j] = InLine[i];
               j++;
          }
     }

     printf("OutPut : %s",OutLineArr);     
     return 0;
}
Comments: