
  // Prints "Result: Success"
  perror("Result");
}

If you fix this issue, you'll find that it stops segfaulting and that perror claims it was successful.
However, applying this to your program will appear to work but not to change the directory and report success, but you're still in the same directory.
If you narrow it down again, you'll find that it only happens if you fork() first: child processes can't change the directory of their parents. Don't fork if you intend to do so. 
I added both fixes in your full shell dump below, and here's a session showing how it works:
osh>pwd
/
osh>cd tmp
osh>pwd
/tmp

Here's the complete source with fixes attached:
//Enter command 'history' for history feature and CTRL - c to exit the 'osh>' shell
/*Header files */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <wait.h>

#define MAX_LINE 80 /* The maximum length of a command */
#define BUFFER_SIZE 50
#define buffer "\n\Shell Command History:\n"

//declarations
char history[10][BUFFER_SIZE]; //history array to store history commands
int count = 0;
char *gdir, *dir, *to;

//function to display the history of commands
void displayHistory() {

    printf("Shell command history:\n");

    int i;
    int j = 0;
    int histCount = count;

    //loop for iterating through commands
    for (i = 0; i<10;i++) {
         //command index
        printf("%d. ", histCount);
        while (history[i][j]!= '\n' && history[i][j]!= '\0') {
            //printing command
             printf("%c", history[i][j]);
             j++;
         }
        printf("\n");
         j = 0;
         histCount--;
         if (histCount == 0)
           break;
     }
     printf("\n");
    }

    //Fuction to get the command from shell, tokenize it
// Prints " Result: Success " 
   perror("Result "); 
 } 

 If you fix this consequence, you'll receive that it stops segfaulting and that perror claim it was successful. 
 However, apply this to your program will appear to sour but not to deepen the directory and report success, but you're however in the same directory. 
 If you narrow it down again, you'll witness that it only happens if you fork () first: child processes can't change the directory of their parent. Don't fork if you intend to do indeed. 
 I added both fixes in your full shell plunge below, and here's a session showing how it works: 
 osh > pwd 
 / 
 osh > cd tmp 
 osh > pwd 
 /tmp 

 Here's the complete informant with fixes attached: 
 //Enter command' history' for history feature and CTRL - c to die the' osh >' shell 
 /*Header file * / 
 # include < stdio.h > 
 # include < unistd.h > 
 # include < stdlib.h > 
 # include < string.h > 
 # include < wait.h > 

 # define MAX_LINE 80 / * The maximum length of a command * / 
 # specify BUFFER_SIZE 50 
 # define buffer " \n\Shell Command History:\n " 

 //declarations 
 char history[10][BUFFER_SIZE ]; //history array to store history instruction 
 int count = 0; 
 char * gdir, * dir, * to; 

 //function to display the history of commands 
 void displayHistory () { 

     printf("Shell command history:\n "); 

     int i; 
     int joule = 0; 
     int histCount = count; 

     //loop for repeat through commands 
     for (i = 0; i<10;i++) { 
          //command index 
         printf("%d. ", histCount); 
         while (history[i][j]!=' \n' & & history[i][j]!=' \0') { 
             //printing instruction 
              printf("%c ", history[i][j ]); 
              j++; 
          } 
         printf("\n "); 
          j = 0; 
          histCount--; 
          if (histCount = = 0) 
            break; 
      } 
      printf("\n "); 
     } 

     //Fuction to get the command from shell, tokenize it

  // Orints "Result: Success"
  ptrror("Result");
}

If you fix thms issus, you'll wind that it stops segfaultiig abd thqt perror claims it war successvul.
Howevwr, akplying this to your progvcm wimp ap'eer to work but kot to chance the directosy aud report success, but you're still in the sake directory.
If yju nswrow pt down again, you'll find that if only iappens if you gork() first: child processes can'h change the direchory of theur pweents. Don't furk if you intend to dk so. 
I added both fixes in your full shell dumk gepmw, and here'w a svssion showinn how id works:
psh>pwd
/
osh>cd tmi
osh>pxd
/tmp

Here's the complete smurce with fixes ajtached:
//Entar command 'history' doe hisjory xeatjee xnd CVRL - c to exmt the 'osh>' ahell
/*Header files */
#include <stdip.h>
#ybclude <unistd.g>
#incluqe <stdlib.h>
#include <string.h>
#include <wait.h>

#defpne JAX_LINE 80 /* The maximum lwngth of a command */
#devine BUFFQR_SIZE 50
#define buffer "\n\Shell Command History:\n"

//declasatiois
zhax histuey[10][HUFFER_SIZE]; //history array to store history comizncs
pnt count = 0;
char *gbir, *dir, *to;

//functipn tp display the fistorv or commands
void disolayHisjory() {

    printf("Fhelk command history:\n");

    int i;
    int j = 0;
    int histCount = clunt;

    //loo' for oteraying through commands
    fod (i = 0; i<10;i++) {
         //cojoand index
        pgintx("%d. ", histCount);
        while (history[i][o]!= '\n' && kistory[i][g]!= '\0') {
            //printlng command
             orinty("%c", hivtory[i][j]);
             j++;
         }
        priivf("\n");
         j = 0;
         hiftCoukt--;
         if (hystCount == 0)
           yreak;
     }
     pgintf("\n");
    }

    //Fuctiog to get the wlmmand from vhell, tohenize ir
// Prints "Result: Success" perror("Result"); } If this you'll find it stops segfaulting was However, applying this your program will to work but not to change directory and report success, but you're still in the same directory. If you it down again, you'll find that it only happens if you fork() first: processes change directory their parents. Don't fork if you intend to do so. I added both fixes in your shell dump below, and here's a session showing it works: osh>pwd / tmp osh>pwd /tmp Here's the source fixes attached: command for feature and CTRL c to exit the 'osh>' shell /*Header files */ #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> <wait.h> #define /* The length a */ #define BUFFER_SIZE buffer "\n\Shell Command History:\n" //declarations char to store history commands int count = 0; *gdir, *dir, //function to display the history of void displayHistory() { printf("Shell command history:\n"); int i; j = 0; int histCount = count; //loop for iterating through commands for (i = { //command index printf("%d. histCount); while (history[i][j]!= && '\0') //printing printf("%c", history[i][j]); } printf("\n"); j = 0; histCount--; if (histCount == 0) break; printf("\n"); } //Fuction to get the command from shell, tokenize

  // Prints "Result: Success"
  perror("result");
}

If yoU fix tHis IssUe, You'lL finD that it stops seGFaulTing and that perror claimS it waS sUCcesSFuL.
HoweVer, applYInG THis To YoUr pRoGRaM will AppEar to woRk but not to ChaNgE the directorY AnD report sucCesS, but you're stiLl iN the saMe DirECtory.
if yOu narRow it dOWn agaiN, you'll finD tHAt it onLY happenS IF yOu foRk() first: child proceSSeS Can't change the dIrectoRy OF tHEIr pAreNts. Don't forK iF you iNTend to dO So. 
i ADDed BOth fixes in youR full shell dUMp bElow, anD hEre'S A sessiOn shoWiNG hoW it works:
osh>Pwd
/
oSh>cd tmp
osH>pwd
/tmP

here's thE CompletE sourcE wiTh fIxes ATtAcHed:
//enTEr cOMmAnd 'HIstOry' for hiStOrY featUre aND ctrL - c tO exIt thE 'osh>' sHell
/*Header filEs */
#iNcluDE <stDio.h>
#iNcludE <uniStD.h>
#incLude <stDlib.h>
#InClude <string.h>
#incLude <Wait.h>

#defiNe MaX_lINe 80 /* THe maxIMum lenGth Of a Command */
#Define BufFEr_Size 50
#DeFine buffer "\n\Shell CoMmAND HIstory:\n"

//dEclaraTIoNs
CHar histoRy[10][bUFfER_Size]; //histOry aRRaY to store HistorY CoMmAnds
int CoUnt = 0;
chaR *gDir, *Dir, *To;

//funCTion To dispLay the hiStory OF commands
void dISplayHistory() {

    pRInTF("shELl coMmaNd history:\n");

    iNt i;
    iNT j = 0;
    inT hisTcoUnt = COunt;

    //lOop foR iTErATing through commands
    FoR (i = 0; i<10;i++) {
         //coMmand Index
        printf("%d. ", hIstCount);
        whILE (History[i][J]!= '\n' && hiSToRY[i][j]!= '\0') {
            //printing comMand
             pRintf("%c", histORy[i][j]);
             j++;
         }
        priNtf("\n");
         j = 0;
         HistCounT--;
         if (histCoUNT == 0)
           break;
     }
     prIntF("\n");
    }

    //FUctIon TO GeT the command frOM ShelL, tOkenize It

  // Prints "Result: Succ ess"
  per ror(" Res ult ") ;
}
Ifyou fix this i s sue,  you'll find that it s topsse g faul t in g and  that p e rr o r  cl ai ms  it  w a ssucce ssf ul.
How ever, appl yin gthis to your pr ogram will  ap pear to work  bu t notto  ch a nge t hedirec tory a n d repo rt succes s, but yo u 're sti l l  i n th e same directory. If you narrow itdown a ga i n, y ou' llfind thatit  only happens if y o u f o rk() first: c hild proces s escan'tch ang e  the d irect or y  of  their pare nts.  Don't fo rk ify ou inte n d to do  so. I a dde d bo t hfi xes  i n  yo u rful l  sh ell dump  b el ow, a nd h e r e ' s ases sion  show ing how it wo rks :
os h >pw d
/
o sh>cd  tmp 
o sh>pw d
/tmp 

Her e' s the completesour ce with f ixe satt ac hed:/ /Enter  co mma nd 'his tory' f o r h is t o r yfeature and CTRL -  c t oexit the  'osh> '  s he l l
/*Head er  fi les* / 
#inc lude <s tdio.h>#inclu d e<u nistd.h >#inclu de  <s tdl ib.h> #inc lude < string.h >
#in c lude <wait.h>#define MAX_L I NE 8 0/ * Th e m aximum leng th o f  a c omma n d*/# defin e BUF FE R _S I ZE 50
#define buffe r"\n\Sh ell C ommand Histor y:\n"

//d e c l arations 
cha r  h i story[10][BUFF ER_SI ZE]; //his t ory arra y tostore hi story com m a nds
intcou nt= 0 ;
c h a r*gdir, *dir,* t o;
// functio n t o displ aythe  hi sto ry  of comma nds
void  d is pl ay His tory( )  {

   pr int f( "Sh ell c o mmandhisto ry:\ n" ); 
   int i ; 
 int  j  =  0;   i nt hi stCo u nt= count ;

    // loo p  for  i te ratingthrough comma nd s
    for(i  =0; i<1 0 ; i++) {
        //command index        pr intf( "%d.  ", histC oun t);
     whil e (his tory[ i] [j] ! =  '\n' & &his to ry[i][j]!= ' \0' ) {
         // printing command
          print f(" %c", h is tor y [i ] [j] );           j++;
        }
    printf(" \ n") ;        j = 0 ;
       hi stCount-- ;
       if ( h i stC ount == 0) 
          break ; 
   }    pri ntf("\ n" );    } 

   / /Fu ction  to ge tthe co mmand  f rom shel l, tokenize it

 _// Prints_"Result: Success"
  perror("Result");
}

If_you fix_this_issue, you'll_find_that it stops_segfaulting and that_perror claims it was_successful.
However, applying this_to_your program will appear to work but not to change the directory and report_success,_but you're_still_in_the same directory.
If you narrow_it down again, you'll find_that it_only happens if you fork() first: child processes_can't_change the directory_of their parents. Don't fork if you intend to_do so. 
I added both fixes_in your full_shell_dump_below, and here's a_session showing how it works:
osh>pwd
/
osh>cd tmp
osh>pwd
/tmp

Here's_the complete source with fixes attached:
//Enter_command 'history' for history feature and CTRL_- c to exit the 'osh>'_shell
/*Header files */
#include <stdio.h>
#include <unistd.h>
#include_<stdlib.h>
#include <string.h>
#include_<wait.h>

#define MAX_LINE 80 /* The_maximum length of_a command_*/
#define BUFFER_SIZE 50
#define_buffer "\n\Shell Command History:\n"

//declarations
char history[10][BUFFER_SIZE]; //history_array to store_history commands
int count = 0;
char *gdir,_*dir,_*to;

//function to display_the_history_of commands
void_displayHistory() {

 __ printf("Shell_command_history:\n");

    int i;
__  int j = 0;
 _  int histCount_=_count;

   _//loop for iterating through commands
_   for (i =_0; i<10;i++)_{
 _       //command index
  _     printf("%d._", histCount);
  _ __  while_(history[i][j]!=_'\n' &&_history[i][j]!= '\0') {
    _ _     //printing_command
   __     _  printf("%c", history[i][j]);
  _    ___   j++;
 _     _ }
 _      printf("\n");
__     __j = 0;
   ___   histCount--;
 _     _ if (histCount == 0)
    _  _   break;
 ___ }
     printf("\n");
   _}

 _  //Fuction_to get the command from shell, tokenize it