использование безопасного sscanf
This commit is contained in:
11
casm/c.c
11
casm/c.c
@@ -1,4 +1,5 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
int sum(int a, int b) {
|
int sum(int a, int b) {
|
||||||
return a+b;
|
return a+b;
|
||||||
@@ -6,10 +7,16 @@ int sum(int a, int b) {
|
|||||||
|
|
||||||
void print(int num) {
|
void print(int num) {
|
||||||
printf("%d\n", num);
|
printf("%d\n", num);
|
||||||
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
int scan() {
|
int scan() {
|
||||||
|
char buffer[100];
|
||||||
int res;
|
int res;
|
||||||
scanf("%d", &res);
|
if (fgets(buffer, sizeof(buffer), stdin) != NULL) {
|
||||||
return res;
|
if (sscanf(buffer, "%d", &res) == 1) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0; // or handle error
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user