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

#define SIZE_LINE 1000+1

char * shorterString(FILE * file, char * const strmin);

int main(void) {
	FILE * file = fopen("parole.txt", "rt");
	
	if (file != NULL) {
		char strmin[SIZE_LINE] = "";
		
		shorterString(file, strmin);
		
		if (strlen(strmin) > 0) {
			printf("Shortest line: %s\n", strmin);
		} else {
			printf("The file or line is empty or invalid.\n");
		}
		
		fclose(file);
	} else {
		perror("Error (source)");
	}
	
	return 0;
}

char * shorterString(FILE * file, char * const strmin) {
	char str[SIZE_LINE];
	int minLength = SIZE_LINE;
	
	while (fgets(str, SIZE_LINE, file) != NULL) {
		int length = strlen(str);
		
		if (str[length - 1] == '\n') {
			length--;
			str[length] = '\0';
		}
		
		if (length < minLength) {
			minLength = length;
			strncpy(strmin, str, length);
			strmin[length] = '\0';
		}
	}
	
	return strmin;
}