Store An Unknown 'Infinite' Amount Of Numbers From User Input Into A Buffer | C Programming Example

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

a shorter code of checking if user inputs the terminating value (-1) :

int main()
{
double buffer[1024];
double input=0;
double total=0;

while(scanf("%lf", &input)==1 && input != -1)
{
buffer[total++] = input;
}
}

drig
Автор

Hey, how would I restructure this to get an infinite number of strings?

pusetsogabert
Автор

Why dont use realloc every time that user adds an int, instead that using a limited size buffer

lukfiorentino
Автор

I have tried this but it's not taking input from command line and if I run using
gcc -o main main.c and click enter to give input as 2 4.4 6 7
Then its directly giving

geetachavan
Автор

Can the program be reworked so that the sentinel is either an empty input string when soliciting input from a user, or when the end of the file is reached, the buffer is closed to new entries, so to speak, and the buffer's contents are displayed to screen?

Mnogojazyk