Write a program which take a file name as a command line argument. Count the number of characters, number of words, number of line, number of vowels and display them on screen.
#include
#include
#include
char buffer[2048];
int main(int argc,char *argv[])
{
int fdold;
int count;
int i,word,space,vovals,line,ch;
word = 0;
space = 0;
vovals = 0;
line = 0 ;
ch=0;
if(argc == 2)
{
fdold = open(argv[1],O_RDONLY);
if(fdold == -1)
{
printf("cannot open file ");
}
else
{
while((count = read(fdold,buffer,sizeof(buffer))) > 0)
{
for (i=0;i {
if(buffer[i] == ' ' || buffer[i] == '.')
{
word++;
}
if(buffer[i] == ' ')
{
space++;
}
if(buffer[i] == 'a' || buffer[i] == 'e' || buffer[i] == 'i' || buffer[i] == 'o' || buffer[i] == 'u' ||
buffer[i] == 'A' || buffer[i] == 'E' || buffer[i] == 'I' || buffer[i] == 'O' || buffer[i] == 'U')
{
vovals++;
}
if(buffer[i] == '\n')
{
line++;
}
}
ch = ch + strlen(buffer);
}
printf("word is : %d\n",word);
printf("Space is : %d\n",space);
printf("Vovals is : %d\n",vovals);
printf("line is : %d\n",line+1);
printf("charector is :%d\n",ch - space);
}
}
else
{
printf("plzz gave a 1 argument..!!");
}
return 0;
}
#include
#include
char buffer[2048];
int main(int argc,char *argv[])
{
int fdold;
int count;
int i,word,space,vovals,line,ch;
word = 0;
space = 0;
vovals = 0;
line = 0 ;
ch=0;
if(argc == 2)
{
fdold = open(argv[1],O_RDONLY);
if(fdold == -1)
{
printf("cannot open file ");
}
else
{
while((count = read(fdold,buffer,sizeof(buffer))) > 0)
{
for (i=0;i
if(buffer[i] == ' ' || buffer[i] == '.')
{
word++;
}
if(buffer[i] == ' ')
{
space++;
}
if(buffer[i] == 'a' || buffer[i] == 'e' || buffer[i] == 'i' || buffer[i] == 'o' || buffer[i] == 'u' ||
buffer[i] == 'A' || buffer[i] == 'E' || buffer[i] == 'I' || buffer[i] == 'O' || buffer[i] == 'U')
{
vovals++;
}
if(buffer[i] == '\n')
{
line++;
}
}
ch = ch + strlen(buffer);
}
printf("word is : %d\n",word);
printf("Space is : %d\n",space);
printf("Vovals is : %d\n",vovals);
printf("line is : %d\n",line+1);
printf("charector is :%d\n",ch - space);
}
}
else
{
printf("plzz gave a 1 argument..!!");
}
return 0;
}
Comments
Post a Comment