I need to get float inputs and only stop when the user hit a ctrl + Z.
However, with my loop like that, my program is needing 3 crtl + Z in sequence. Does anyone know how exactly to stop it with EOF?
This is my code:
I have the while loop condition analyzing if the input was a float.
int capacity = 5;
double* numSet = (double*)malloc(capacity * sizeof(*numSet));
if (numSet == NULL)
return NULL;
double number;
char ch = 0;
while (fscanf_s(stdin,"%lf", &number) == 1)
{
numSet[size] = number;
size++;
if (size == capacity)
{
double* numSetDouble = realloc(numSet, (capacity *= 2) * sizeof(*numSetDouble));
if (numSetDouble == NULL)
{
free(numSet);
return NULL;
}
numSet = numSetDouble;
}
}
return numSet;
I need the loop to stop when the user enters ctrl ^ Z