Update cv3/program.c
This commit is contained in:
		
							parent
							
								
									e19a7ed823
								
							
						
					
					
						commit
						50804be2f7
					
				| @ -63,12 +63,17 @@ int read(struct stack *s) { | ||||
|     } | ||||
| 
 | ||||
|     float value; | ||||
|     int scan = sscanf(temp, "%f", &value); | ||||
|     char extra; | ||||
|     int scan = sscanf(temp, "%f %c", &value, &extra); | ||||
| 
 | ||||
|     // If it's a number
 | ||||
|     // If it's a properly formatted number
 | ||||
|     if (scan == 1) { | ||||
|         push_stack(s, value); | ||||
|         print_stack(s); | ||||
|     } else if (scan > 1) { | ||||
|         // If extra characters were found, it's an invalid input like .23.4
 | ||||
|         printf("bad input\n"); | ||||
|         exit(0); | ||||
|     } else { | ||||
|         switch (temp[0]) { | ||||
|             case '+': | ||||
| @ -102,13 +107,14 @@ int read(struct stack *s) { | ||||
|             } | ||||
|             default: | ||||
|                 printf("bad input\n"); | ||||
|                 exit(0); // Continue on invalid input
 | ||||
|                 exit(0); // Exit on invalid input
 | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     return 1; // Continue the loop
 | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| int main() { | ||||
|     struct stack my_stack; | ||||
|     init(&my_stack); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user