usaa24/cv3/program.c

41 lines
752 B
C
Raw Normal View History

2024-10-08 13:28:33 +00:00
#include<stdio.h>
#include<stdlib.h>
2024-10-08 13:45:13 +00:00
#include<string.h>
#include<ctype.h>
#include<assert.h>
2024-10-08 13:28:33 +00:00
#define LINE_SIZE 100
#define STACK_SIZE 100
struct stack{
float values[LINE_SIZE];
int size;
}
void print_stack(struct stack* stack){
for (int i = 0; i < stack->size; i++){
printf("%.0f", stack->values[i]);
}
printf("\n");
}
int main(){
2024-10-08 13:45:13 +00:00
char input[LINE_SIZE]; float y; struct stack mystack;
memset(&mystack, 0, sizeof(struct stack));
2024-10-08 13:28:33 +00:00
while(fgets(input, LINE_SIZE, stdin) != NULL){
input[strlen(input - 1)] = '\0';
if(sscanf(input, "\f", &y) == 1){
printf("Success!\n");
assert(mystack.size < STACK_SIZE);
mystack.values[mystack.size] = y;
mystack.size ++;
2024-10-08 13:45:13 +00:00
} else{
2024-10-08 13:28:33 +00:00
return 1;
}
print_stack(&mystack);
}
return 0;
}