Receive an integer input until an opening character is found in C

Asked 2 years ago, Updated 2 years ago, 51 views

Enter space and save it in an integer array until you get a line character in C language I want to print them out in order. The maximum number of integers to be entered is not more than 100.)

Enter

5 6 10 1 2
Output
5 6 10 1 2

I want to receive it like this, what should I do?

int t;
while(~scanf("%d",&t)){
    ...
}

I think there was a way to do this. Is there any other way?

c file-io algorithm

2022-09-22 18:16

1 Answers

// Enter code here

// Performing an iterative operation
while(1) {
   // Receive integer input

   // Verify that the entered value is an open character
   if (?) {
       // Escape the Roof Door
       break;
   }

   // If not, add a value to the array
}

// Array Output
for (inti=0; i<Total length of array; i++) {
   printf("%d", array[i]);
}

// Enter code here
// Is the opening character output?
char a;

scanf_s("%c", &a);
printf("%c", a);


2022-09-22 18:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.