Here is what i'm trying to do: My teacher gave me an assignment to recieve input from a user like "1,2,3,4,-3,17,-9,0,5,-8,10" and after the user has pressed enter key the program should ignore the "," signs and print the maximum and minimum values of the positive and negative numbers (each). now he said we should use getchar() to do this but I don't understand how... I know that this function is used to read a single character from the user (and than print it with putchar() ) and not for ignoring characters, so I would like to understand how I should use it to do this kind of operation in a while loop.
So to summarize my question is about selectively reading the input (the other things I will manage myself although if someone sees something in the code and can give a tip I would be happy but im looking to understand the getchar() function to do the opposite of what i'm reading it designed to do), I have wrote and deleted the code thousands of times and couldn't get it to work... this is what it looks like now (and it doesn't work):
#include <stdio.h>
#include <stdlib.h>
int main(){
char enter = "\n";
int list_of_nums[100];
char ch1[100];
int neg_num[100];
int pos_num[100];
printf("please enter numbers separated by ',': \n");
while (getchar()!= enter) {
scanf("%d" ,&list_of_nums;
if (list_of_nums >= 0){
getchar();
pos_num.append(list_of_nums);
}
else{
neg_num.append(list_of_nums);
}
}
int max_pos = max.pos_num[];
int min_pos = min.pos_num[];
int max_neg = max.neg_num[];
int min_pos = min.neg_num[];
printf("the maximum number of all the positives is: %d \n" ,max_pos);
printf("the minimum number of all the positives is: %d \n" ,min_pos);
printf("the maximum number of all the negatives is: %d \n" ,max_neg);
printf("the minimum number of all the negatives is: %d \n" ,min_neg);
return 0;
}