I'm trying to take user input containing a bunch of space delimited 1-3 digit numbers using scanf() and storing them into an int array and printing each seperate one on a new line to test but it's not working. Here is what I have so far:
#include <stdio.h> #include <string.h> int main() { int sourceArr[500]; int i = 0; printf("\nEnter ciphertext: \n"); while (scanf("%d", &sourceArr[i++]) == 1); for (int j=0;j<500;j++) { printf("%d\n", sourceArr[j]); } } so the user is asked to input a sequence of numbers like so:
Enter ciphertext: 23 122 32 and I want to store 23 in sourceArr[0], 122 in sourceArr[1] and 32 in sourceArr[2] and then print each one like so:
23 122 32 But the program idles right after entering the input and won't print the numbers.
forloop tofor (int j = 0; j < i-1; j++)so you don't print more than what you read.