The manual page says scanf() usually returns the numbers of items read. So you could make your loop similar to:
while (scanf(...) == 1) {
...
}
As for storing the integers: if you know nothing about dynamic memory allocation, you can use a "large" fixed array. So your code would look something along of:
#define MAX_ITEMS 50
int list[MAX_ITEMS];
int list_size = 0;
while(scanf("%d", &num) == 1) {
if (list_size == MAX_ITEMS) {
exit("list too big")
}
list[list_size++] = num;
}
(Code not checked: expect bugs.)
==
@Martin wrote: "Thanks a lot, but this still doesn't work, because the loop ends only if I type a letter"
You need to signal end of input (to the whole program) by pressing Ctrl+D (after ENTER; on Linux) or Ctrl+Z (after ENTER, probably; on Windows/DOS).
But if you need to feed more input to the program afterwards then this technique isn't suitable for you (Sorry for not noticing that this might indeed have been your case). Probably the simplest solution is to use a "sentry value": stop reading the list if you see a special value like -1 or 999.
Other solutions:
(1) Read the whole line (by using fgets() or getline() or whatever) and then parse it yourself, as @jplatt39 suggested.
(2) Re-organize your program so it reads the list as its last input. Or read the list via the command-line, as @jplatt39 suggested, and the other input via scanf().
(3) Use getc() till a digit (or newline) it met and then ungetc() it if it's a digit so the next scanf() can see it.
As you see, scanf() isn't suitable for "complicated" input. For "complicated" input programmers use a "regular expressions" library, or they write a lexer (and/or parser), or they use a library for a common format like YAML or XML or JSON.