Skip to content

Commit cd9d3c3

Browse files
committed
printf input
1 parent 0034dd8 commit cd9d3c3

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

01_SimpleCApp/SimpleCApp.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
#include <stdint.h>
33

44
int32_t f(int32_t x);
5+
int scan_x(int32_t* x);
56
void print_fx(int32_t x, int32_t y);
67

78
int main()
89
{
9-
// (I) Simulate input (TODO: Replace with proper input)
10-
int32_t x = 5;
10+
// (I)
11+
int32_t x = 0;
12+
int result = scan_x(&x);
13+
printf("Read %i parameters from user input. ", result);
1114

1215
// (P)
1316
int32_t y1 = f(1 * x);
@@ -27,6 +30,12 @@ int32_t f(int32_t x)
2730
return x * x + 5 * x + 5;
2831
}
2932

33+
int scan_x(int32_t* x)
34+
{
35+
printf("Enter the value x: ");
36+
return scanf_s("%i", x);
37+
}
38+
3039
void print_fx(int32_t x, int32_t y)
3140
{
3241
printf("f(%i) = %i, ", x, y);

0 commit comments

Comments
 (0)