why this code not produce any reaction on any command

#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
#include<stdlib.h>
void count(char c,char *fn)
{
int lc=0,wc=0,cc=0,handle;
char ch;
if(handle=open(fn,O_RDONLY)==-1)
{
printf("File %s fail to open",fn);
return;
}
while(read(handle,&ch,1)!=0)
{
if(ch==' '||ch=='\n')
{
wc++;
}else
cc++;
}
if(ch=='\n')
{
lc++;
}

close(handle);
switch(c)
{
case 'c':
printf("Total No. Of Character==%d\n",cc);break;
case 'w':
printf("Total No. Of Character==%d\n",wc);break;
case 'l':
printf("Total No. Of Character==%d\n",lc);break;
}
}

main()
{
char command[80],t1[20],t2[20],t3[20],t4[20];
int n;
system("clear");
while(1)
{
printf("rushiShell@");
fflush(stdin);
fgets(command,80,stdin);
n=sscanf(command,"%s %s %s %s",t1,t2,t3,t4);
switch(n)
{
case '1':
if(strcmp(t1,"exit")==0)
exit(1);
else
if(!fork())
{
execlp(t1,t2,NULL);
perror(t1);
}break;
case '2':
if(!fork())
{
execlp(t1,t2,t3,NULL);
perror(t1);
}break;
case '3':
if(strcmp(t1,"count")==0)
count(t2[0],t3);
else
{
if(!fork())
{
execlp(t1,t2,t3,t4,NULL);
perror(t1);
}
}break;
case '4':
if(!fork())
{
execlp(t1,t1,t2,t3,t4,NULL);
perror(t1);
}
}
}
}

To find out what's happening in the program, you can apply a simple technique called "debugging".

In this case:
* Add some traces, to print out all variables at all steps, to your code so you know what's happening with each input.
* use a debugger.

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.