Name this program unique c The program takes one or more co

Name this program unique. c - The program takes one or more command line arguments. Each argument consists of only upper- and lower-case letters. Your program should output the number of different letters (if you see both uppercase A and lowercase a in the arguments, they are considered as the same letter appearing twice) that exist on the argument list. Sample executions are shown below: ./a.out Hello World There are 7 different letters in Hello World ./a.out Alabama Crimson Tide There are 13 different letters in Alabama Crimson Tide ./a.out aaaaaaaaaa B AAAAAAAAAA b There are 2 different letters in aaaaaaaaaa B AAAAAAAAAA b

Solution

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[])
{

int i,j,a[26],len,num,count=0,ascii;
char str[50];

for (i=0;i<26;i++)
   a[i] = 0;

for (i=1; i<argc; i++)
{
strcpy(str, argv[i]);
len = strlen(str);
   for (j=0; j<len; j++)
   {
       ascii = str[j];
       if (ascii >= 65 && ascii <= 90)
       {
           str[j] = str[j]+32;
       }
       num = str[j] - \'a\';
       a[num] = a[num] + 1;
   }
}

for (i=0; i<26; i++)
   if (a[i] != 0)
       count++;

printf(\"There are %d different letters in \",count);

for (i=1; i<argc; i++)
   printf(\"%s \",argv[i]);

printf(\"\ \");

return 0;
}

 Name this program unique. c - The program takes one or more command line arguments. Each argument consists of only upper- and lower-case letters. Your program

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site