Program description:

To be edited...

Your code:

Make file

words: words.c
	gcc -o words words.c -I.
clean:
	rm *.o *.err

.c File

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


int main(int argc, char **argv){
	
	extern char *optarg;
	extern int optind;
	int c, err = 0; 
	int lflag=0, sflag=0, wordLength=0, count=0, max=0, min=0;
	char *token, str[100], *longestStr, *shortestStr;
	FILE *filename;
	static char usage[] = "usage: words [-l] [-s] [filename]";
        
	/*Checks usage input for -l or -s*/
	while ((c = getopt(argc, argv, "ls")) != -1)
		switch (c) {
		case 'l':
			lflag = 1;
			break;
		case 's':
			sflag = 1;
			break;
		case '?':
			err = 1;
			break;
		}
	if (err) {
		fprintf(stderr, usage, argv[0]); /*Usage message and exit if error*/
		exit(1);
	}

	if (argv[optind] == NULL) { /*If no filename, get string input by user*/
		printf("Please input a string of words: \n");
		fgets(str,100,stdin);
	} else { /*If filename, get string input from file*/
		filename = fopen(argv[optind], "r");
		fgets(str,100,filename);
	}
	
	token = strtok(str, " .,?!\n"); /*Sets token as the first word from the string input*/ 
	
	max = strlen(token); /*sets max length as length of token*/
	min = strlen(token); /*sets min length as length of token*/
	longestStr = token; /*sets longest string as token*/
	shortestStr = token; /*sets shortest string as token*/
	
	while(token != NULL){ /*while token is not empty, find word count of string, as well as longest and shortest words*/
		
		wordLength = strlen(token); /*sets wordLenght as token length*/
		if(wordLength > max){ /*Finds longest word*/
			max = strlen(token);
			longestStr = token;
		} else if (wordLength < min){ /*Finds shortest word*/
			min = strlen(token);
			shortestStr = token;
		}
		
		token = strtok(NULL, " .,?!\n"); /*Finds next word in string input and sets it as token*/
		count++; /*Counts words*/
	}
	
	
	if(lflag == 1){ /*Prints longest word if -l*/
		printf("Longest word: \"%s\"\n", longestStr);
	}
	
	if(sflag == 1){ /*Prints shortest word if -s*/
		printf("Shortest word: \"%s\"\n", shortestStr);
	}
	
	printf("Total count of words: %d\n", count); /*Prints total count of words*/
	

	exit(0);
}

All the assignments will be posted. Subscribe for more! :)