aboutsummaryrefslogtreecommitdiffstats
path: root/reworking
diff options
context:
space:
mode:
authormjfernez <mjfernez@gmail.com>2020-02-12 21:04:06 -0500
committermjfernez <mjfernez@gmail.com>2020-02-12 21:04:06 -0500
commitc9d153b6dafc1018fd7fad08677cade7332e2df0 (patch)
tree9f5b40d36264d40c8de06f3d529207b5c30b057f /reworking
parente970ec8268bae2d175a76018535220052e4f2edf (diff)
downloadProject_Euler_Solutions-c9d153b6dafc1018fd7fad08677cade7332e2df0.tar.gz
Update README. update reworking
Diffstat (limited to 'reworking')
-rwxr-xr-xreworking/wordnumsbin17296 -> 17416 bytes
-rw-r--r--reworking/wordnums.c48
2 files changed, 30 insertions, 18 deletions
diff --git a/reworking/wordnums b/reworking/wordnums
index 8510dee..f30a9da 100755
--- a/reworking/wordnums
+++ b/reworking/wordnums
Binary files differ
diff --git a/reworking/wordnums.c b/reworking/wordnums.c
index ad57107..5f48400 100644
--- a/reworking/wordnums.c
+++ b/reworking/wordnums.c
@@ -14,17 +14,17 @@ const char *tens[10] = {"","", "twenty", "thirty", "forty",
const char *nd = "AND";
-int lengthOfName(char *num){
+int lengthOfName(char *num) {
char *word;
// minus 1 for null terminator
int digits = strlen(num) - 1;
int n = atoi(num);
- if(digits == 1){
+ printf("The num is now %s", num, digits);
+ if(digits == 1) {
word = (char *) ones[n];
printf("%s\n", word);
return strlen(word);
- }
- if(digits == 2){
+ } else if(digits == 2) {
// if the first digit, ie. the tens column is 1
if(num[0] == '1'){
word = (char *) teens[n % 10];
@@ -36,31 +36,43 @@ int lengthOfName(char *num){
word = (char *) tens[n / 10];
printf("%s\n", word);
return strlen(word);
- }
- else{
- // since the input to the function expects a null terminator, an extra '\n' is needed
-
- /// substring would be a better way to do this
+ } else {
+ // since the input to the function expects a null terminator,
+ // an extra '\n' is needed
char o[2];
int on;
word = (char *) tens[n / 10];
printf("%s", word);
- o[0] = num[1];
- o[1] = '\n';
+ strncpy(o, &num[1], 2);
+ printf("%s", o);
on = lengthOfName(o);
- //return (strlen(word) + lengthOfName(o));
return (strlen(word) + on);
}
+ } else if(digits == 3) {
+ printf("HERE\n\n");
+ word = (char *) ones[n / 100];
+ printf("%shundred", word);
+ if(num[1] == '0' && num[2] == '0') {
+ printf("\n");
+ return strlen(word) + strlen("hundred");
+ } else {
+ char t[3];
+ int te;
+ strncpy(t, &num[1], 3);
+ printf("%s", nd);
+ te = lengthOfName(t);
+ // example: the user inputs, num = 121
+ // one hundred AND twenty one
+
+ ////this line breaks the program for some reason
+ //return (strlen(word) + strlen("hundred") + strlen(nd) + te);
+ }
}
- if(digits == 3){
- word = (char *) ones[n / 100]
- int t = lengthOfName(
- }
- // error condition
+ // error condition for debugging, i.e. in case I messed up, return something
return -1;
}
-int main(){
+int main() {
// 4 is the max for this example, +1 for null terminator or if user tries to cheat
char n[5];
int out;