Add documentatin for calc()
This commit is contained in:
parent
7bcacfecac
commit
92b51776b6
1 changed files with 11 additions and 1 deletions
12
netcalc.c
12
netcalc.c
|
@ -72,6 +72,12 @@ int prepsocket(struct addrinfo *ainfo) {
|
||||||
return SOCKFD;
|
return SOCKFD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Does the calculation
|
||||||
|
/// @param num1 first operand
|
||||||
|
/// @param num2 second operand
|
||||||
|
/// @param op operator
|
||||||
|
/// @param result stores the result of the calculation
|
||||||
|
/// @return 0 on success, -1 on failure
|
||||||
int calc(unsigned int num1, unsigned int num2, char op, unsigned int *result) {
|
int calc(unsigned int num1, unsigned int num2, char op, unsigned int *result) {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case '+':
|
case '+':
|
||||||
|
@ -101,6 +107,10 @@ int calc(unsigned int num1, unsigned int num2, char op, unsigned int *result) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Converts a string into an integer using its base
|
||||||
|
/// @param numstr input string
|
||||||
|
/// @param num stores the decoded integer
|
||||||
|
/// @return 0 on failure, the encoded base of the integer on success
|
||||||
int base(char *numstr, unsigned int *num) {
|
int base(char *numstr, unsigned int *num) {
|
||||||
short base = 10;
|
short base = 10;
|
||||||
|
|
||||||
|
@ -116,7 +126,7 @@ int base(char *numstr, unsigned int *num) {
|
||||||
*num = (unsigned int) test;
|
*num = (unsigned int) test;
|
||||||
return base;
|
return base;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue