/*
 * Program to search for string in line of text.
 * Search string is given as a command-line argument.
 */
#include <stdio.h>
#include <string.h>

int main(int argc, char * argv[]) {
	if (argc < 2) {
		/* 
		 * my preferred format for printing messages about
		 * command-line arguments
		 */
		printf("usage:  %s search_string\n", argv[0]);
		return 1;
	}

	char line[80];
	printf("enter a line of text\n");
	fgets(line, sizeof line, stdin);
	char *nl = strchr(line, '\n');
	if (nl == NULL) {
		printf("line too long\n");
		return 1;
	}

	char *search = strstr(line, argv[1]);
	if (search == NULL) {
		printf("not found\n");
	}
	else {
		/* note use of pointer arithmetic to find position */
		printf("found at position %ld\n", search-line);
	}
	return 0;
}