Program Description:
Ask the user to input however many positive and negative numbers they would like (spaces between numbers). Count and display number of positive and negative numbers.
The Problem:
My solution for this problem was to put each number in one of two arrays 'positive' or 'negative'. Then output the count of each array. I just don't know how to store each number that is inputted by the user. It would be easier if I knew how many numbers was going to be inputted but oh well:P
I am still new to C and have grown accustomed to using fgets and sscanf, so I hope thats ok. However, I put '???' in the third argument of sscanf because I am not sure what do put there. Just looking for a little guidance, thanks people
The Code:
Code:/* Exercise 7-6 : Write a program that takes a series of numbers and counts the number of positive and negative values. */ /* Exercise 7-6 : Write a program that takes a series of numbers and counts the number of positive and negative values. */ #include<stdio.h> char line[100]; //read line input int listPosNums[]; //will hold negative list of numbers int listNegNums[]; //will hold positive list of numbers int main(void) { printf("Please enter a list of positive and negative numbers (separated by spaces): "); fgets(line, sizeof(line), stdin); sscanf(line, "%d%n", ???); return 0; }