Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- void myfgets(char names [][50] , int len );
- void longest (char names [][50] , int len);
- void shortest (char names [][50] , int len);
- void alphabetOrder(char names [][50] , int len);
- int main (void)
- {
- char names [10][50] = {0};
- myfgets(names , 10);
- shortest(names , 10);
- longest(names , 10);
- alphabetOrder(names , 10);
- return (0);
- }
- void myfgets(char names [][50] , int len )
- {
- int i = 0;
- for(i=0; i<len; i++)
- {
- fgets(names[i] , 50 , stdin);
- names[i][strcspn(names[i],"\n")]=0;
- }
- }
- void longest (char names [][50] , int len)
- {
- int max = 0;
- int i = 0;
- int index = 0;
- for(i=0; i<len; i++)
- {
- if(max<strlen(names[i]))
- {
- max = strlen(names[i]);
- index = i;
- }
- }
- printf(" the longes name is: %s\n" , names[index]);
- }
- void shortest (char names [][50] , int len)
- {
- int min = 0;
- int i = 0;
- int index = 0;
- min = 51;
- for(i=0; i<len; i++)
- {
- if(min>strlen(names[i]))
- {
- min = strlen(names[i]);
- index = i;
- }
- }
- printf(" the shortest name is: %s\n" , names[index]);
- }
- void alphabetOrder(char names [][50] , int len)
- {
- int first = 0;
- int last = 0;
- int i = 0;
- for(i = 0; i<len; i++)
- {
- if(strcmp(names[i] , names[first])<0)
- {
- first = i;
- }
- if(strcmp(names[i] , names[last])>0)
- {
- last = i;
- }
- }
- printf("the first name is: %s\n" , names[first]);
- printf("the last name is: %s\n" , names[last]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement