Go to the source code of this file.
Functions | |
char* | intToChar (int i) |
Dirty little function that converts an integer to a string. More... | |
int | charToInt (char* s) |
Dirty little function that converts an string to a integer. More... |
|
Dirty little function that converts an string to a integer.
Definition at line 82 of file intToChar.cpp.
00082 { 00083 int i; 00084 00085 i = 0; 00086 00087 for (int a = strlen (s); a >= 0; a--) { 00088 if ((s[a] >= '0') && (s[a] <= '9')) { 00089 i += (((int) s[a]) - 48) * ((int) pow (10.0, (double) (strlen (s) - a - 1))); 00090 }; 00091 }; 00092 00093 if (strncmp (s, "=", 1) == 0) { 00094 i = 0 - i; 00095 }; 00096 00097 return i; 00098 }
|
Dirty little function that converts an integer to a string.
Definition at line 30 of file intToChar.cpp.
00030 { 00031 int digits; 00032 int vorz; 00033 int j; 00034 int m; 00035 00036 if (i < 0) { 00037 j = -i; 00038 vorz = 0; 00039 } else { 00040 j = i; 00041 vorz = 1; 00042 }; 00043 00044 m = j; 00045 for (int a = 1; a < 10; a++) { 00046 if ((m / 10) < 1) { 00047 digits = a; 00048 a = 10; 00049 }; 00050 m = m / 10; 00051 }; 00052 00053 00054 char* tmp; 00055 tmp = (char*) malloc (digits + 2 - vorz); 00056 00057 m = j; 00058 for (int a = digits; a >= 1; a--) { 00059 tmp[a - vorz]= (char) (48 + (m % 10)); 00060 m = m / 10; 00061 }; 00062 00063 if (vorz == 0) { 00064 tmp[0] = '-'; 00065 }; 00066 00067 tmp[digits + 1 - vorz] = '\0'; 00068 00069 return tmp; 00070 }