I'm trying to build up my own small library to deal with calculations of huge numbers over the limit of int or double. I know there are some useful libraries for this purpose, but I am just having a try to do it myself.
The code below, I cannot find an error and neither can the compiler (gcc of MinGW). It simply does not run. I re-read the code multiple times, but still cannot understand why my computer refuses to run it. I am using Windows 7, by the way. Any help or suggestions would be grateful.
(The code is intended to print 11111............111111111.11111)
#include <stdio.h>
#include <stdlib.h>
#define PLUS 10
#define MINUS 11
void myprint(char f[]);
int getlen(char f[]);
void daeip(char f[], char g[]);
/*
(len: the length of the array f[])
f[len - 3]: start of the number; the number part is from f[f[len - 3]] to f[0]
f[len - 2]: number of decimals
f[len - 1]: plus or minus
*/
int main(){
char f[100], g[100];
int i;
for(i=0;i<50;i++){
f[i] = '1';
}
f[100 - 3] = 49;
f[100 - 2] = 5;
f[100 - 1] = MINUS;
daeip(f, g);
myprint(g);
return 0;
}
void myprint(char f[]){
int i;
int len = getlen(f);
if(f[len - 1] == MINUS){
printf("-");
}
for(i = f[len - 3]; i >= 0; i--){
printf("%s", f[i]);
if(i == f[len - 2]) printf(".");
}
}
int getlen(char f[]){
int len = sizeof(f)/sizeof(f[0]);
return len;
}
void daeip(char f[], char g[]){
int flen = getlen(f);
int glen = getlen(g);
int i;
for(i=0; i <= f[flen - 3]; i++){
g[i] = f[i];
}
g[glen - 3] = f[flen - 3];
g[glen - 2] = f[flen - 2];
g[glen - 1] = f[flen - 1];
}