C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
iloan.c File Reference

Installment Loan Calculator. More...

#include <math.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
Include dependency graph for iloan.c:

Go to the source code of this file.

Macros

#define FALSE   0
#define TRUE   1

Functions

void ABEND (int e)
 The ABEND function is a signal handler that is called when the program receives certain signals (e.g., SIGINT, SIGQUIT, SIGHUP). It takes an integer argument representing the signal number and prints an error message indicating that an abnormal end (ABEND) has occurred, along with the signal number. After displaying the message, it exits the program with a failure status.
double accept_i ()
 The accept_i function prompts the user to enter the annual interest rate for the loan. It validates the input to ensure it is numeric and non-negative. If the input is invalid, an error message is displayed, and the user is prompted to enter the value again until a valid input is provided.
double accept_n ()
 The accept_n function prompts the user to enter the number of payments for the loan. It validates the input to ensure it is numeric and non-negative. If the input is invalid, an error message is displayed, and the user is prompted to enter the value again until a valid input is provided.
double accept_pmt ()
double accept_pv ()
 The following functions are used to accept user input for the present value, number of payments, interest rate, and payment amount. They validate the input to ensure it is numeric and meets the required conditions (e.g., non-negative). If the input is invalid, an error message is displayed, and the user is prompted to enter the value again.
void accept_str (char *s)
 The accept_str function prompts the user with a given string and reads input from the standard input into a buffer. It uses the fprintf function to display the prompt and the read function to capture the user's input. The input is stored in the global buffer in_str, which can be used by other functions for further processing.
double calculate_i (double pv, double n, double pmt)
 The calculate_i function calculates the annual interest rate for a loan based on the present value, number of payments, and payment amount. It uses an iterative method to find the interest rate that satisfies the loan equation. If any of the input values are zero, it displays an error message and prompts the user to provide valid inputs.
double calculate_n (double pv, double i, double pmt)
 The calculate_n function calculates the number of payments required to pay off a loan based on the present value, interest rate, and payment amount. It uses logarithmic functions to compute the result. If any of the input values are zero, it displays an error message and prompts the user to provide valid inputs.
double calculate_pmt (double pv, double n, double i)
 The calculate_pmt function calculates the payment amount for a loan based on the present value, number of payments, and interest rate. It uses the formula for the payment amount of an annuity to compute the result. If any of the input values are zero, it displays an error message and prompts the user to provide valid inputs.
double calculate_pv (double n, double i, double pmt)
 The calculate_pv function calculates the present value of a loan based on the number of payments, interest rate, and payment amount. It uses the formula for the present value of an annuity to compute the result. If any of the input values are zero, it displays an error message and prompts the user to provide valid inputs.
void error_press_any_key (char *s)
 The error_press_any_key function is a utility function that displays an error message to the user and waits for them to press any key before continuing. It takes a string argument that contains the error message to be displayed. After the user presses a key, it prints two newlines for formatting.
char * format_currency (float a)
 The format_currency function takes a floating-point number as input and formats it as a currency string. It adds commas as thousand separators and ensures that the number is displayed with two decimal places. The function uses a static buffer to store the formatted string and returns a pointer to that buffer. The formatted string is right-aligned and padded with spaces if necessary.
char * format_interest (float a)
 The format_interest function takes a floating-point number representing an interest rate and formats it as a string with five decimal places. It uses a static buffer to store the formatted string and returns a pointer to that buffer. The formatted string is left-aligned and padded with spaces if necessary.
int is_numeric (char *s)
 The is_numeric function checks if a given string consists of numeric characters, including digits, decimal points, and commas. It iterates through each character in the string and returns FALSE if it encounters any character that is not a digit, a decimal point, or a comma. If all characters are valid, it returns TRUE.
int main (int argc, char **argv)
 iloan is a trivial application to demonstrate how a command-line program can be integrated into C-Menu Form with simple file, argument, or pipe i-o.
void numbers (char *d, char *s)
 The numbers function takes two character pointers as arguments: a destination pointer (d) and a source pointer (s). It iterates through the characters in the source string (s) and copies only the numeric characters (digits, decimal points, and minus signs) to the destination string (d). The function effectively filters out any non-numeric characters from the source string and constructs a new string containing only the valid numeric characters. Finally, it null-terminates the destination string.

Variables

int f_i = 0
int f_n = 0
int f_pmt = 0
int f_pv = 0
bool f_quiet = false
char in_str [BUFSIZ+1]

Detailed Description

Installment Loan Calculator.

Author
Bill Waller Copyright (c) 2025 MIT License billx.nosp@m.wall.nosp@m.er@gm.nosp@m.ail..nosp@m.com
Date
2026-02-09

Definition in file iloan.c.

Macro Definition Documentation

◆ FALSE

#define FALSE   0

Definition at line 18 of file iloan.c.

◆ TRUE

#define TRUE   1

Definition at line 19 of file iloan.c.

Function Documentation

◆ ABEND()

void ABEND ( int e)

The ABEND function is a signal handler that is called when the program receives certain signals (e.g., SIGINT, SIGQUIT, SIGHUP). It takes an integer argument representing the signal number and prints an error message indicating that an abnormal end (ABEND) has occurred, along with the signal number. After displaying the message, it exits the program with a failure status.

Definition at line 419 of file iloan.c.

419 {
420 printf("ABEND: Error %d:\n", e);
421 exit(EXIT_FAILURE);
422}

Referenced by main().

Here is the caller graph for this function:

◆ accept_i()

double accept_i ( )

The accept_i function prompts the user to enter the annual interest rate for the loan. It validates the input to ensure it is numeric and non-negative. If the input is invalid, an error message is displayed, and the user is prompted to enter the value again until a valid input is provided.

Definition at line 227 of file iloan.c.

227 {
228 double i;
229 while (1) {
230 accept_str("Rate (annual) - - -> ");
231 if (in_str[0] == '\0') {
232 i = 0;
233 break;
234 } else {
235 if (is_numeric(in_str)) {
236 i = atof(in_str);
237 if (i < 0)
238 error_press_any_key("interest Rate can't be less than 0");
239 else
240 break;
241 } else
242 error_press_any_key("Interest Rate must be numeric");
243 }
244 }
245 return (i);
246}
char in_str[BUFSIZ+1]
Definition iloan.c:20
void error_press_any_key(char *)
The error_press_any_key function is a utility function that displays an error message to the user and...
Definition iloan.c:268
void accept_str(char *s)
The accept_str function prompts the user with a given string and reads input from the standard input ...
Definition iloan.c:363
int is_numeric(char *)
The is_numeric function checks if a given string consists of numeric characters, including digits,...
Definition iloan.c:353

References accept_str(), error_press_any_key(), in_str, and is_numeric().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ accept_n()

double accept_n ( )

The accept_n function prompts the user to enter the number of payments for the loan. It validates the input to ensure it is numeric and non-negative. If the input is invalid, an error message is displayed, and the user is prompted to enter the value again until a valid input is provided.

Definition at line 210 of file iloan.c.

210 {
211 double n;
212 while (1) {
213 accept_str("Number of Payments > ");
214 if (is_numeric(in_str)) {
215 n = atof(in_str);
216 if (n < 0)
217 error_press_any_key("Number of Payments can't be less than 0");
218 else
219 break;
220 } else
221 error_press_any_key("Number of Payments must be numeric");
222 }
223 return (n);
224}

References accept_str(), error_press_any_key(), in_str, and is_numeric().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ accept_pmt()

double accept_pmt ( )

brief The accept_pmt function prompts the user to enter the payment amount for the loan. It validates the input to ensure it is numeric and non-negative. If the input is invalid, an error message is displayed, and the user is prompted to enter the value again until a valid input is provided.

Definition at line 249 of file iloan.c.

249 {
250 double pmt;
251 while (1) {
252 accept_str("Payment Amount - -> ");
253 if (in_str[0] == '\0') {
254 pmt = 0;
255 break;
256 } else {
257 if (is_numeric(in_str)) {
258 pmt = atof(in_str);
259 break;
260 } else
261 error_press_any_key("Payment Amount must be numeric");
262 }
263 }
264 return (pmt);
265}

References accept_str(), error_press_any_key(), in_str, and is_numeric().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ accept_pv()

double accept_pv ( )

The following functions are used to accept user input for the present value, number of payments, interest rate, and payment amount. They validate the input to ensure it is numeric and meets the required conditions (e.g., non-negative). If the input is invalid, an error message is displayed, and the user is prompted to enter the value again.

Definition at line 188 of file iloan.c.

188 {
189 double pv;
190 while (1) {
191 accept_str("Present Value - - -> ");
192 if (in_str[0] == '\0') {
193 pv = 0;
194 break;
195 } else {
196 if (is_numeric(in_str)) {
197 pv = atof(in_str);
198 if (pv < 0)
199 error_press_any_key("Present Value can't be less than 0");
200 else
201 break;
202 } else
203 error_press_any_key("Present Value must be numeric");
204 }
205 }
206 return (pv);
207}

References accept_str(), error_press_any_key(), in_str, and is_numeric().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ accept_str()

void accept_str ( char * s)

The accept_str function prompts the user with a given string and reads input from the standard input into a buffer. It uses the fprintf function to display the prompt and the read function to capture the user's input. The input is stored in the global buffer in_str, which can be used by other functions for further processing.

Definition at line 363 of file iloan.c.

363 {
364 fprintf(stderr, "%s", s);
365 read(0, in_str, BUFSIZ);
366}
#define BUFSIZ
Definition view.h:31

References in_str.

Referenced by accept_i(), accept_n(), accept_pmt(), and accept_pv().

Here is the caller graph for this function:

◆ calculate_i()

double calculate_i ( double pv,
double n,
double pmt )

The calculate_i function calculates the annual interest rate for a loan based on the present value, number of payments, and payment amount. It uses an iterative method to find the interest rate that satisfies the loan equation. If any of the input values are zero, it displays an error message and prompts the user to provide valid inputs.

Definition at line 302 of file iloan.c.

302 {
303 double i1 = 0, i;
304 double delta = 0.0000001;
305 double xdelta;
306 double fdelta;
307 double fprimi;
308 double ffact;
309 double fi;
310 double fman;
311 double fmann;
312 if (pv == 0 || n == 0 || pmt == 0)
314 "3 non-zero values required to calculate Interest Rate");
315 ffact = pv / pmt;
316 xdelta = 0;
317 if (ffact < n) {
318 i1 = 0.0125;
319 xdelta = 0.9;
320 }
321 while (xdelta > delta) {
322 fman = 1 / (1 + i1);
323 fmann = pow(fman, n);
324 fi = ffact * i1 + fmann - 1;
325 fprimi = ffact - n * fmann * fman;
326 fdelta = fi / fprimi;
327 i1 = i1 - fdelta;
328 if (fdelta < 0)
329 xdelta = -fdelta;
330 else
331 xdelta = fdelta;
332 }
333 i = i1 * 1200;
334 if (!f_quiet)
335 printf("interest Rate - - - - - -> %s\n", format_interest(i));
336 return (i);
337}
bool f_quiet
Definition iloan.c:41
char * format_interest(float)
The format_interest function takes a floating-point number representing an interest rate and formats ...
Definition iloan.c:409

References error_press_any_key(), f_quiet, and format_interest().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculate_n()

double calculate_n ( double pv,
double i,
double pmt )

The calculate_n function calculates the number of payments required to pay off a loan based on the present value, interest rate, and payment amount. It uses logarithmic functions to compute the result. If any of the input values are zero, it displays an error message and prompts the user to provide valid inputs.

Definition at line 289 of file iloan.c.

289 {
290 double i1, n;
291 if (pv == 0 || i == 0 || pmt == 0)
292 error_press_any_key("3 non-zero values required to calculate "
293 "Number of Payments");
294 i1 = i / 1200;
295 n = -log(1 - pv * i1 / pmt) / log(1 + i1);
296 if (!f_quiet)
297 printf("Number of Payments - - -> %s\n", format_currency(n));
298 return (n);
299}
char * format_currency(float)
The format_currency function takes a floating-point number as input and formats it as a currency stri...
Definition iloan.c:369

References error_press_any_key(), f_quiet, and format_currency().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculate_pmt()

double calculate_pmt ( double pv,
double n,
double i )

The calculate_pmt function calculates the payment amount for a loan based on the present value, number of payments, and interest rate. It uses the formula for the payment amount of an annuity to compute the result. If any of the input values are zero, it displays an error message and prompts the user to provide valid inputs.

Definition at line 340 of file iloan.c.

340 {
341 double i1, pmt;
342 if (pv == 0 || n == 0 || i == 0)
344 "3 non-zero values required to calculate Payment Amount");
345 i1 = i / 1200;
346 pmt = pv * i1 / (1 - pow(1 + i1, -n));
347 if (!f_quiet)
348 printf("Payment Amount - - - - -> %s\n", format_currency(pmt));
349 return (pmt);
350}

References error_press_any_key(), f_quiet, and format_currency().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculate_pv()

double calculate_pv ( double n,
double i,
double pmt )

The calculate_pv function calculates the present value of a loan based on the number of payments, interest rate, and payment amount. It uses the formula for the present value of an annuity to compute the result. If any of the input values are zero, it displays an error message and prompts the user to provide valid inputs.

Definition at line 275 of file iloan.c.

275 {
276 double i1, pv;
277
278 if (n == 0 || i == 0 || pmt == 0)
280 "3 non-zero values required to calculate Present Value");
281 i1 = i / 1200;
282 pv = pmt * (1 - pow(1 + i1, -n)) / i1;
283 if (!f_quiet)
284 printf("Present Value - - - - - -> %s\n", format_currency(pv));
285 return (pv);
286}

References error_press_any_key(), f_quiet, and format_currency().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ error_press_any_key()

void error_press_any_key ( char * s)

The error_press_any_key function is a utility function that displays an error message to the user and waits for them to press any key before continuing. It takes a string argument that contains the error message to be displayed. After the user presses a key, it prints two newlines for formatting.

Definition at line 268 of file iloan.c.

268 {
269 printf("%s", s);
270 getc(stdin);
271 printf("\n\n");
272}

Referenced by accept_i(), accept_n(), accept_pmt(), accept_pv(), calculate_i(), calculate_n(), calculate_pmt(), calculate_pv(), and main().

Here is the caller graph for this function:

◆ format_currency()

char * format_currency ( float a)

The format_currency function takes a floating-point number as input and formats it as a currency string. It adds commas as thousand separators and ensures that the number is displayed with two decimal places. The function uses a static buffer to store the formatted string and returns a pointer to that buffer. The formatted string is right-aligned and padded with spaces if necessary.

Definition at line 369 of file iloan.c.

369 {
370 int digit_count, left_of_point;
371 static char sstr[80];
372 static char fstr[80];
373 char *src_ptr, *dst_ptr, *sptr, *FPtr;
374
375 sprintf(sstr, "%-18.2f", a);
376 sptr = sstr;
377 src_ptr = sstr;
378 FPtr = fstr;
379 dst_ptr = fstr;
380 while (*src_ptr++ != '\0')
381 ;
382 src_ptr -= 2;
383 left_of_point = FALSE;
384 digit_count = 0;
385 while (src_ptr >= sptr) {
386 if (left_of_point) {
387 if (*src_ptr >= '0' && *src_ptr <= '9') {
388 if (digit_count == 3) {
389 *dst_ptr++ = ',';
390 digit_count = 1;
391 } else
392 digit_count++;
393 }
394 } else if (*src_ptr == '.')
395 left_of_point = TRUE;
396 *dst_ptr++ = *src_ptr--;
397 }
398 src_ptr = dst_ptr - 1;
399 dst_ptr = sptr;
400 while (src_ptr >= FPtr)
401 *dst_ptr++ = *src_ptr--;
402 while (*--dst_ptr == ' ')
403 ;
404 *++dst_ptr = '\0';
405 return (sptr);
406}
#define TRUE
Definition iloan.c:19
#define FALSE
Definition iloan.c:18

Referenced by calculate_n(), calculate_pmt(), calculate_pv(), and main().

Here is the caller graph for this function:

◆ format_interest()

char * format_interest ( float a)

The format_interest function takes a floating-point number representing an interest rate and formats it as a string with five decimal places. It uses a static buffer to store the formatted string and returns a pointer to that buffer. The formatted string is left-aligned and padded with spaces if necessary.

Definition at line 409 of file iloan.c.

409 {
410 static char sstr[80];
411 char *s;
412
413 sprintf(sstr, "%-3.5f", a);
414 s = sstr;
415 return (s);
416}

Referenced by calculate_i(), and main().

Here is the caller graph for this function:

◆ is_numeric()

int is_numeric ( char * s)

The is_numeric function checks if a given string consists of numeric characters, including digits, decimal points, and commas. It iterates through each character in the string and returns FALSE if it encounters any character that is not a digit, a decimal point, or a comma. If all characters are valid, it returns TRUE.

Definition at line 353 of file iloan.c.

353 {
354 char c;
355
356 while ((c = *s++) != '\0' && c != '\n')
357 if ((c < '0' || c > '9') && c != '.' && c != ',')
358 return (FALSE);
359 return (TRUE);
360}

Referenced by accept_i(), accept_n(), accept_pmt(), and accept_pv().

Here is the caller graph for this function:

◆ main()

int main ( int argc,
char ** argv )

iloan is a trivial application to demonstrate how a command-line program can be integrated into C-Menu Form with simple file, argument, or pipe i-o.

Positional arguments: present_value The present value of the loan (the amount borrowed). number_of_payments The total number of payments to be made. interest_rate The annual interest rate (as a percentage). payment_amount The amount of each payment. The program calculates the missing value based on the three provided values. For example, if the present value, number of payments, and interest rate are provided, it will calculate the payment amount. If the present value, interest rate, and payment amount are provided, it will calculate the number of payments, and so on. The program can be used in a non-interactive way by passing the four values as arguments, with the value to be calculated set to 0. For example, to calculate the payment amount for a $10,000 loan with a 5% annual interest rate and 60 monthly payments, you could run:

iloan 10000 60 5 0

This is proof-of-concept code, and is not intended for production use. It is not designed to be robust, and does not handle all edge cases or input errors. It is intended solely to demonstrate how a simple command-line program can be integrated into C-Menu Form. In the future, more sophisticated abstractions, such as async event handlers, serialization, rpc, database, and a standardized plugin interface will be integrated into C-Menu. Feel free to modify and enhance this code as needed, but please do not use it in production without proper testing and validation. It is provided as-is without any warranty or support. Use at your own risk.

Definition at line 74 of file iloan.c.

74 {
75 double pv = 0, pmt = 0, i = 0, n = 0;
76 char tmp_str[BUFSIZ];
77
78 signal(SIGINT, ABEND);
79 signal(SIGQUIT, ABEND);
80 signal(SIGHUP, ABEND);
81
82 if (argc > 1 &&
83 ((strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0) ||
84 argc < 4)) {
85 printf("Usage: iloan [present_value number_of_payments "
86 "interest_rate payment_amount]\n\n");
87 exit(EXIT_SUCCESS);
88 }
89 if (argc > 4) {
90 numbers(tmp_str, argv[1]);
91 sscanf(tmp_str, "%lf", &pv);
92 sscanf(argv[2], "%lf", &n);
93 sscanf(argv[3], "%lf", &i);
94 numbers(tmp_str, argv[4]);
95 sscanf(tmp_str, "%lf", &pmt);
96 if (pv != 0)
97 f_pv = 1;
98 if (n != 0)
99 f_n = 1;
100 if (i != 0)
101 f_i = 1;
102 if (pmt != 0)
103 f_pmt = 1;
104 if (f_pv + f_n + f_i + f_pmt < 3) {
106 "Error: At least three values must be greater than zero.");
107 exit(EXIT_FAILURE);
108 }
109 f_quiet = true;
110 } else {
111 if (argc != 1) {
112 printf("Usage: iloan [present_value number_of_payments "
113 "interest_rate payment_amount]\n\n");
114 exit(EXIT_FAILURE);
115 } else {
116 if (argc == 1) {
117 printf("\nInstallment Loan Calculator\n\n");
118 printf("Three of these values must be greater than 0. The "
119 "field\n");
120 printf("with a value of 0 will be calculated.\n\n");
121 while (f_pv + f_n + f_i + f_pmt < 3) {
122 if (pv == 0) {
123 pv = accept_pv();
124 if (pv != 0)
125 f_pv = 1;
126 }
127 if (n == 0) {
128 n = accept_n();
129 if (n != 0)
130 f_n = 1;
131 }
132 if (i == 0) {
133 i = accept_i();
134 if (i != 0)
135 f_i = 1;
136 }
137 if (pmt == 0) {
138 pmt = accept_pmt();
139 if (pmt != 0)
140 f_pmt = 1;
141 }
142 if (f_pv + f_n + f_i + f_pmt < 3) {
143 error_press_any_key("Error: At least three values must "
144 "be greater than zero.");
145 }
146 }
147 printf("\nYou entered:\n\n");
148 if (pv != 0)
149 printf("Present Value - - - - - -> %s\n",
150 format_currency(pv));
151 if (n != 0)
152 printf("Number of Payments - - -> %s\n",
153 format_currency(n));
154 if (i != 0)
155 printf("Interest Rate - - - - - -> %s\n",
156 format_interest(i));
157 if (pmt != 0)
158 printf("Payment Amount - - - - -> %s\n",
159 format_currency(pmt));
160 printf("\n\nCalculation result:\n\n");
161 }
162 }
163 }
164 if (pv == 0)
165 pv = calculate_pv(n, i, pmt);
166 else if (n == 0)
167 n = calculate_n(pv, i, pmt);
168 else if (i == 0)
169 i = calculate_i(pv, n, pmt);
170 else if (pmt == 0)
171 pmt = calculate_pmt(pv, n, i);
172
173 if (f_quiet) {
174 printf("%s\n", format_currency(pv));
175 printf("%s\n", format_currency(n));
176 printf("%s\n", format_interest(i));
177 printf("%s\n", format_currency(pmt));
178 }
179 signal(SIGINT, SIG_DFL);
180 signal(SIGQUIT, SIG_DFL);
181 signal(SIGHUP, SIG_DFL);
182}
int f_n
Definition iloan.c:38
double accept_n()
The accept_n function prompts the user to enter the number of payments for the loan....
Definition iloan.c:210
double calculate_i(double, double, double)
The calculate_i function calculates the annual interest rate for a loan based on the present value,...
Definition iloan.c:302
void numbers(char *d, char *s)
The numbers function takes two character pointers as arguments: a destination pointer (d) and a sourc...
Definition iloan.c:425
double accept_pmt()
Definition iloan.c:249
double accept_pv()
The following functions are used to accept user input for the present value, number of payments,...
Definition iloan.c:188
void ABEND(int)
The ABEND function is a signal handler that is called when the program receives certain signals (e....
Definition iloan.c:419
double calculate_pmt(double, double, double)
The calculate_pmt function calculates the payment amount for a loan based on the present value,...
Definition iloan.c:340
int f_i
Definition iloan.c:39
double calculate_pv(double, double, double)
The calculate_pv function calculates the present value of a loan based on the number of payments,...
Definition iloan.c:275
double accept_i()
The accept_i function prompts the user to enter the annual interest rate for the loan....
Definition iloan.c:227
int f_pv
Definition iloan.c:37
int f_pmt
Definition iloan.c:40
double calculate_n(double, double, double)
The calculate_n function calculates the number of payments required to pay off a loan based on the pr...
Definition iloan.c:289

References ABEND(), accept_i(), accept_n(), accept_pmt(), accept_pv(), calculate_i(), calculate_n(), calculate_pmt(), calculate_pv(), error_press_any_key(), f_i, f_n, f_pmt, f_pv, f_quiet, format_currency(), format_interest(), and numbers().

Here is the call graph for this function:

◆ numbers()

void numbers ( char * d,
char * s )

The numbers function takes two character pointers as arguments: a destination pointer (d) and a source pointer (s). It iterates through the characters in the source string (s) and copies only the numeric characters (digits, decimal points, and minus signs) to the destination string (d). The function effectively filters out any non-numeric characters from the source string and constructs a new string containing only the valid numeric characters. Finally, it null-terminates the destination string.

Definition at line 425 of file iloan.c.

425 {
426 while (*s != '\0') {
427 if (*s == '-' || *s == '.' || (*s >= '0' && *s <= '9'))
428 *d++ = *s++;
429 else
430 s++;
431 }
432 *d = '\0';
433}

Referenced by main().

Here is the caller graph for this function:

Variable Documentation

◆ f_i

int f_i = 0

Definition at line 39 of file iloan.c.

Referenced by main().

◆ f_n

int f_n = 0

Definition at line 38 of file iloan.c.

Referenced by main().

◆ f_pmt

int f_pmt = 0

Definition at line 40 of file iloan.c.

Referenced by main().

◆ f_pv

int f_pv = 0

Definition at line 37 of file iloan.c.

Referenced by main().

◆ f_quiet

bool f_quiet = false

Definition at line 41 of file iloan.c.

Referenced by calculate_i(), calculate_n(), calculate_pmt(), calculate_pv(), and main().

◆ in_str

char in_str[BUFSIZ+1]
Examples
/usr/local/src/C-Menu/src/enterstr.c.

Definition at line 20 of file iloan.c.

Referenced by accept_i(), accept_n(), accept_pmt(), accept_pv(), and accept_str().