File:  [MW Coherent from dump] / coherent / d / usr / src / examples / abs.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:38 2019 UTC (7 years, 2 months ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent

#include <ctype.h>
#include <stdio.h>
main()
{
	extern char *gets();
	extern int atoi();
	char string[64];
	int counter;
	int input;

	printf("Enter an integer: ");
	fflush(stdout);
	gets(string);

	for (counter=0; counter < strlen(string); counter++) {
		input = string[counter];
		if (!isascii(input)) {
			fprintf(stderr,
				"%s is not ASCII\n", string);
			exit(1);
		}
		if (!isdigit(input))
			if (input != '-' || counter != 0) {
				fprintf(stderr,
					"%s is not a number\n", string);
				exit(1);
			}
	}

	input = atoi(string);
	printf("abs(%d) is %d\n", input, abs(input));
	exit(0);
}


unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.