~hamblingreen/practical-c

e46087bac699d2d39276833af202a65ac9b64c64 — Robert Hamblin 2 years ago c02ce5a
 add new program
5 files changed, 64 insertions(+), 0 deletions(-)

A posneg/Makefile
A posneg/README
A posneg/posneg
A posneg/posneg.c
A posneg/posneg.o
A posneg/Makefile => posneg/Makefile +7 -0
@@ 0,0 1,7 @@
#
# Makefile for the program posneg
#
# Turn on debugging
CFLAGS=-g
posneg:posneg.o
	$(CC) $(CFLAGS) -o posneg posneg.o

A posneg/README => posneg/README +12 -0
@@ 0,0 1,12 @@
posneg -- Calculate the number of positive and negative numbers in a
data set

By hamblingreen <hamblingreen@hotmail.com> 

Purpose: Calculate the number of positive and negative numbers in a data
set. To be small, fast, well-documented, and demonstrate the life cycle
of a simple C program.

Usage: Type in numbers seperated by spaces

Reference: Steve Oualline

A posneg/posneg => posneg/posneg +0 -0
A posneg/posneg.c => posneg/posneg.c +45 -0
@@ 0,0 1,45 @@
/****************************************
* posneg -- Calculate the number of	*
*   positive and negative numbers in a	*
*   data set				*
* Author: hamblingreen			*
*   <hamblingreen@hotmail.com>		*
* Purpose: Calculate the number of	*
*   positive and negative numbers in a	*
*   data set. To be small, fast, well-	*
*   documented, and demonstrate the	*
*   life cycle of a simple C program.	*
* Usage: Type in numbers seperated by	*
*   spaces				*
* Reference: Steve Oualline		*
****************************************/

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

char	line[100];	/* user input line */
char	input[100];	/* manipulated input */
int	positive;	/* tally of positive numbers */
int	negative;	/* tally of negative numbers */
int	zeroes;	/* tally of zeroes in the data set*/

main() {
	while (1) {
		(void) strcpy(input, "0"); /* exit if user does not input data */

		/* read user input */
		(void) printf("Enter data seperated by spaces: ");
		(void) fgets(line, sizeof(line), stdin);
		(void) sscanf(line, "%s", &input);

		/* cycle through numbers, tallying up positive and negative values */
		(void) printf("%s \n", input);
		
		/* display user output 
		(void) printf("There are %d positive numbers and %d negative numbers in the supplied data set.\n", positive, negative);

*/

	}
	return (0);
}

A posneg/posneg.o => posneg/posneg.o +0 -0