char* pValue::toStr() { int i1, i2; char *tval = new char[16]; switch(type) { case SHORTINT: return fcvt(*(short*)data, 0, &i1, &i2); break; case INTEGER: return fcvt(*(int*)data, 0, &i1, &i2); break; case DOUBLE: gcvt(*(double*)data, 8, tval); return tval; break; case STRING: return data; break; default: //BUG return NULL; }; }
LPTSTR CArborEdit::FloatToString(LPTSTR buff,double r) { _TCHAR *buffer; LPTSTR startbuffptr; int dec,sign; // must use static, don't assume SS==DS int i; startbuffptr = buff; if (EditStyleIs(EDIT_CURRENCY)) { buffer = fcvt((double)r, m_iCurDigits, &dec, &sign); *buff++ = m_cCurrency1; if( m_cCurrency2 != ' ') *buff++ = m_cCurrency2; // copy the negative sign if less than zero if (sign) *buff++ = '-'; if( dec <= 0 ) *buff++ = '0'; // copy the non-fractional part before the decimal place for(i=0; i<dec; i++) { if( ((dec-i) % 3 ) == 0 && (i !=0 ) ) *buff++ = m_cThousand; *buff++ = *buffer++; } // copy the decimal point into the string *buff++ = m_cDecimal; if ( dec < 0 ) for( i = 1; i <= m_iCurDigits && i <= (dec * (-1)); *buff++ = '0', i++ ); } else if(EditStyleIs(EDIT_FLOAT)) { buffer = fcvt((double)r, m_iNumberOfDigits, &dec, &sign); // copy the negative sign if less than zero if (sign) *buff++ = '-'; if( dec <= 0 ) *buff++ = '0'; // copy the non-fractional part before the decimal place for(i=0; i<dec; *buff++ = *buffer++, i++); // copy the decimal point into the string *buff++ = '.'; if ( dec < 0 ) for( i = 1; i <= m_iNumberOfDigits && i <= (dec * (-1)); *buff++ = '0', i++ ); } else return buff; *buff = '\0'; // don't assume NULL termination // copy the fractional part after the decimal place lstrcat(buff,buffer); buff = startbuffptr; return startbuffptr; }
int main(void) { double value; char *pstr; int dec, sign; value=3.1415926535; pstr=fcvt(value,6,&dec,&sign); printf("문자열 : %s, 소수점 위치 : %d, 부호는 %d,",pstr,dec,sign); value=-3.1415926535; pstr=fcvt(value,8,&dec,&sign); printf("문자열 : %s, 소수점 위치 : %d, 부호는 %d,",pstr,dec,sign); return 0; }
CStringEx CTypeUnitDouble::FormatDouble( const double dvalue ) const { int decimal, sign; char *buffer; if( dvalue == 0 ) return( CStringEx( "0.0" )); #ifdef NL_OS_WINDOWS buffer = _fcvt( dvalue, 5, &decimal, &sign ); #else buffer = fcvt( dvalue, 5, &decimal, &sign ); #endif // NL_OS_WINDOWS CStringEx sx( buffer ); if( decimal <= 0 ) { sx = (std::string)(CStringEx( "0." ) + CStringEx( '0', -decimal ) + sx); } else sx.insert(decimal,"."); while( sx[sx.length()-1] == '0' ) sx.left( (int)sx.length() -1 ); if( sx[sx.length()-1] == '.' ) sx += '0'; if( sign ) sx = CStringEx( "-" + sx ); return sx; }
int printf(char *fmt,...){ int next=0; va_list ap; va_start(ap,fmt); while(*fmt){ if(*fmt=='%'){ next=*(fmt+1); if(next=='l') next++; if(next=='d') { char buf[100]; puts(itoa(va_arg(ap,int),buf,10)); } if(next=='s') puts(va_arg(ap,char*)); if(next=='f') { /**/ int p,v; double d=va_arg(ap,double); /* char buf[50]; gcvt(d,10,buf); printf(buf); */ char *pt=fcvt(d,10,&p,&v); int r=0; while(*pt){ if(r==p) putchar('.'); putchar(*pt); pt++; r++; } }
static void special (void) { int decpt, sign, res; char *p; char buf [1024]; p = ecvt (NAN, 10, &decpt, &sign); if (sign != 0 || strcmp (p, "nan") != 0) output_error ("ecvt", NAN, 10, "nan", 0, 0, p, decpt, sign); p = ecvt (INFINITY, 10, &decpt, &sign); if (sign != 0 || strcmp (p, "inf") != 0) output_error ("ecvt", INFINITY, 10, "inf", 0, 0, p, decpt, sign); /* Simply make sure these calls with large NDIGITs don't crash. */ (void) ecvt (123.456, 10000, &decpt, &sign); (void) fcvt (123.456, 10000, &decpt, &sign); /* Some tests for the reentrant functions. */ /* Use a too small buffer. */ res = ecvt_r (123.456, 10, &decpt, &sign, buf, 1); if (res == 0) { printf ("ecvt_r with a too small buffer was succesful.\n"); ++error_count; } res = fcvt_r (123.456, 10, &decpt, &sign, buf, 1); if (res == 0) { printf ("fcvt_r with a too small buffer was succesful.\n"); ++error_count; } }
static double SliderIntervalRound(double fValue, double fInterval, double fMin, double fMax, WORD wParam) { if (fInterval == 0.0) return fValue; if (fValue > fMax) return fMax; else if (fValue < fMin) return fMin; if ((double) (long) fInterval == fInterval && (double) (long) fValue == fValue) { int dec, sign; return atof(fcvt(fValue, 0, &dec, &sign)); } else { double dInterval = fInterval / 100000; if (wParam == SB_LINEUP) { fValue = floor((fValue - fMin) / dInterval) * dInterval + fMin; return ceil(fValue * 100000) / 100000; } else { fValue = ceil((fValue - fMin) / dInterval) * dInterval + fMin; return floor(fValue * 100000) / 100000; } } }
int main (int argc, char * argv[]) { double valeur; int nb_chiffres; int position; int signe; char * retour; if ((argc != 3) || (sscanf(argv[1], "%lf", & valeur) != 1) || (sscanf(argv[2], "%d", & nb_chiffres) != 1)) { fprintf(stderr, "Syntaxe : %s valeur nb_chiffres \n", argv[0]); exit (EXIT_FAILURE); } retour = ecvt(valeur, nb_chiffres, & position, & signe); fprintf(stdout, "ecvt() = %s \n", retour); fprintf(stdout, " position = %d \n", position); fprintf(stdout, " signe = %d \n", signe); retour = fcvt(valeur, nb_chiffres, & position, & signe); fprintf(stdout, "fcvt() = %s \n", retour); fprintf(stdout, " position = %d \n", position); fprintf(stdout, " signe = %d \n", signe); return EXIT_SUCCESS; }
/* * Returns a null terminated formatted string. * If error is encountered, such as malloc() failed, then return NULL. * The caller of this function should beware that the return value is * a static buffer declared within this function and the value of it may * change. */ char * cm_printf(double value, int decimal_pt) { int sign = 0; int deci_pt = 0; int buf_cnt = 0; int formatted_cnt = 0; int buf_len = 0; char *buf = NULL; static char *formatted = NULL; if ( formatted != NULL ) { free(formatted); formatted = NULL; } if ( (value == (double)0) && (decimal_pt == 0) ) { formatted = (char *)cm_strdup("0"); return formatted; } if ( (buf = (char *)malloc(DBL_SIZE + decimal_pt)) == NULL ) { return (char *)NULL; } if ( (formatted = (char *)calloc(1, DBL_SIZE + decimal_pt)) == NULL ) { free(buf); return (char *)NULL; } #ifdef SunOS fconvert(value, decimal_pt, &deci_pt, &sign, buf); #elif defined(CSRG_BASED) snprintf(buf, decimal_pt, "%f", value); #else /* this version, available on the HP and AIX machine is not reentrant. */ strcpy(buf, fcvt(value, decimal_pt, &deci_pt, &sign)); #endif if ( sign ) { strcpy(formatted, "-"); } buf_len = deci_pt + decimal_pt; if ( deci_pt ) { strncat(formatted, buf, deci_pt); } else { /* zero */ strcat(formatted, "0"); } if ( deci_pt == buf_len ) { strcat(formatted, "\0"); free(buf); return formatted; } strcat(formatted, "."); for ( formatted_cnt = strlen(formatted), buf_cnt = deci_pt; buf_cnt < buf_len; buf_cnt++, formatted_cnt++ ) { formatted[formatted_cnt] = buf[buf_cnt]; } formatted[formatted_cnt] = '\0'; free(buf); return formatted; }
int main() { int decimal, sign; char *buffer; double source = 3.1415926535; buffer = fcvt(source, 7, &decimal, &sign); printf("source: %2.10f buffer: '%s' decimal: %d sign: %d\n", source, buffer, decimal, sign); }
void testValues() { f = 2; int d,n; char* result = fcvt(anydouble(), anyint(), &d, &n); //@ assert \valid(result); //@ assert f == 2; //@ assert vacuous: \false; }
double conversion(float w) { int punto_d,signo; char*cadena; double r,s; cadena=fcvt(w,4,&punto_d,&signo); r=atof(cadena); w=r/10000; if (signo==1) w = w * (-1); return(w); }
/*double conversion(float w) { int punto_d,signo; char*cadena; double r,s; cadena=fcvt(w,4,&punto_d,&signo); r=atof(cadena); w=r/10000; if (signo==1) w = w * (-1); return(w); }*/ double conversion(double w) { cadena=fcvt(valor,5,&punto_d,&signo); r=atof(cadena); valor2=r/100000; if (signo==1) valor2 = valor2 * (-1); divi=valor2/0.0001; cadena2=fcvt(valor,4,&punto_d,&signo); valor3=atoi(cadena2); resta= valor3 - divi; if (resta > 0 ) { w= (valor3 - 1)* 0.0001; } if (resta < 0) { w = valor3 * 0.0001; } return(w); }
RGString RGXmlDataFractionDigits :: BuildString (const RGPScalar& p, int& param1, int& param2) { int fractionalDigits = SizeLimit; char* str; double d = p.GetDouble (); int decimalPoint; int sign; str = fcvt (d, fractionalDigits, &decimalPoint, &sign); RGString Result = str; param1 = decimalPoint; param2 = sign; return Result; }
CString Speller::GetFract(double d,int prec){ if(!prec)return ""; d-=floor(d); int i,j; LPTSTR ts; if(prec<0){ ts=fcvt(d,20,&i,&j); if('0'==*ts)return ""; for(LPTSTR tail=ts+19;ts<tail;tail--){ if('0' == *tail)*tail='\0'; //убираем конечные нули else break; //до 1-го ненулевого символа. } CString rez('0',i); rez+=ts; return rez; } d+=1; ts=fcvt(d,prec,&i,&j); CString rez(ts+1); return rez; }
char *code_message(msg *a){ char *coded_msg=(char *)malloc(sizeof(int)*5+sizeof(double)+300*sizeof(char)+20); coded_msg[0]='\0'; char num[10]; snprintf(num,10,"%d",a->sender_id); strcat(coded_msg,num); strcat(coded_msg," "); snprintf(num,10,"%d",a->receiver_id); strcat(coded_msg,num); strcat(coded_msg," "); snprintf(num,10,"%d",a->msg_type); strcat(coded_msg,num); strcat(coded_msg," "); int dec_pl,sign; strcat(coded_msg,fcvt((double) a->timestamp, 0, &dec_pl, &sign)); strcat(coded_msg," "); snprintf(num,10,"%d",a->coming_from); strcat(coded_msg,num); strcat(coded_msg," "); snprintf(num,10,"%d",a->message_id); strcat(coded_msg,num); strcat(coded_msg," "); strcat(coded_msg," "); strcat(coded_msg,a->message); // puts("This is encoded string:"); // puts(coded_msg); return coded_msg; }
int Algoritms::SaveStates(char *name,char *AlgTaskName[maxcrits], char *AlgProcName[3],task far* tasklistptr) { int handle,retvalue; UINT MaxLgTakt,MaxLgProc,MaxLgTask; UCHAR NumbTask=0,NumbProc=0; char *CopyRight= " ╔════════════════════════════════════════════════════════════════════════════╗\n" " ║ PARALLEL PROCESSOR SCHEDULER ║\n" " ║ Version 1.1 ║\n" " ║ (C) Feedback ║\n" " ╚════════════════════════════════════════════════════════════════════════════╝\n\n"; char *value= " \n"; char *AlgTaskMsg= " Алгоритм выбора задач: \n"; char *AlgProcMsg= " - по минимуму индекса \n" " Алгоритм выбора процессоров: \n" " - \n" " - по минимуму индекса \n"; char *TitleMessage= " Число Задач: Число процессоров: Критический путь: \n" " ┌─────────────┬────────────┬───────────────────┬─────────────────┐ \n" " │ Номер │ Номер │ Время постановки │ Время окончания │ \n" " │ задачи │ процессора │ на выполнение │ решения │ \n" " ├─────────────┼────────────┼───────────────────┼─────────────────┤ \n"; char *Mesg= " │ │ │ │ │ \n"; char *TitleDone= " └─────────────┴────────────┴───────────────────┴─────────────────┘ \n" " Время решения => \n" " Коэффициенты загруженности процессоров : \n"; char *Charge= " Процессор : Время работы => Загруженность => 0. \n"; char *Str= "\n────────────────────────────────────────────────────────────────────────────────\n\n"; tasks=tasklistptr; itoa(time,value,10); MaxLgTakt=strlen(value); itoa(cntprocs,value,10); MaxLgProc=strlen(value); itoa(cnttasks,value,10); MaxLgTask=strlen(value); if ((handle= open(name,O_APPEND|O_TEXT|O_RDWR,S_IREAD|S_IWRITE))==-1) { if ((handle= open(name,O_CREAT|O_APPEND|O_TEXT|O_RDWR,S_IREAD|S_IWRITE))==-1) return io_error; if (write(handle,CopyRight,80*5+1)!=80*5+1) { close(handle); return io_error; } } if (write(handle,AlgTaskMsg,71)!=71) { close(handle); return io_error; } for (int i=1; i<=cntcrits; i++) { strcpy(value," - "); strcpy(&value[6],AlgTaskName[critslist[i]-1]); if (write(handle,value,71)!=71) { close(handle); return io_error; } } strcpy(&AlgProcMsg[71*2+6],AlgProcName[charge]); if (write(handle,AlgProcMsg,71*4)!=71*4) { close(handle); return io_error; } strcpy(value,AlgTaskName[critslist[i]-1]); itoa(cnttasks,value,10); strcpy(&TitleMessage[15],value); itoa(cntprocs,value,10); strcpy(&TitleMessage[41],value); itoa(critway,value,10); strcpy(&TitleMessage[66],value); if (write(handle,TitleMessage,71*5)!=71*5) { close(handle); return io_error; } while (++NumbTask<=cnttasks) { itoa(NumbTask,value,10); strcpy(&Mesg[7+MaxLgTask-strlen(value)],value); itoa(taskstate[NumbTask].procnumber,value,10); strcpy(&Mesg[21+MaxLgProc-strlen(value)],value); itoa(taskstate[NumbTask].begtime,value,10); strcpy(&Mesg[37+MaxLgTakt-strlen(value)],value); itoa(taskstate[NumbTask].begtime+tasks[NumbTask].weight-1,value,10); strcpy(&Mesg[56+MaxLgTakt-strlen(value)],value); if (write(handle,Mesg,71)!=71) { close(handle); return io_error; } strcpy(&Mesg[7]," "); strcpy(&Mesg[21]," "); strcpy(&Mesg[37]," "); strcpy(&Mesg[56]," "); } itoa(time-1,value,10); strcpy(&TitleDone[89],value); if (write(handle,TitleDone,71*3)!=71*3) { close(handle); return io_error; } while (++NumbProc<=cntprocs) { int dec,sign; double kfc; itoa(NumbProc,value,10); strcpy(&Charge[14+MaxLgProc-strlen(value)],value); itoa(procs[NumbProc].chargetime,value,10); strcpy(&Charge[38+MaxLgTakt-strlen(value)],value); kfc=((float)procs[NumbProc].chargetime)/((float)(time-1)); value=fcvt(kfc,5,&dec,&sign); if (procs[NumbProc].chargetime!=time-1) strcpy(&Charge[63],value); else strcpy(&Charge[61],"1.00000"); if (write(handle,Charge,71)!=71) { close(handle); return io_error; } strcpy(&Charge[14]," :"); if (procs[NumbProc].chargetime!=time-1) strcpy(&Charge[63]," "); else strcpy(&Charge[61],"0. "); } write(handle,Str,82); close(handle); return io_ok; }
/* * Convert a floating point number to a string formats 'f', 'e' or 'E'. * The result is placed in buf, and len denotes the length of the string * The sign is returned in the is_negative argument (and is not placed * in buf). Always add decimal point if add_dp is YES. */ static char * conv_fp(char format, double num, boolean_e add_dp, int precision, bool_int * is_negative, char buf[], int *len) { char *s = buf; char *p; int decimal_point; if (format == 'f') p = fcvt(num, precision, &decimal_point, is_negative); else /* either e or E format */ p = ecvt(num, precision + 1, &decimal_point, is_negative); /* * Check for Infinity and NaN */ if (isalpha(*p)) { *len = strlen(strcpy(buf, p)); *is_negative = FALSE; return (buf); } if (format == 'f') if (decimal_point <= 0) { *s++ = '0'; if (precision > 0) { *s++ = '.'; while (decimal_point++ < 0) *s++ = '0'; } else if (add_dp) *s++ = '.'; } else { while (decimal_point-- > 0) *s++ = *p++; if (precision > 0 || add_dp) *s++ = '.'; } else { *s++ = *p++; if (precision > 0 || add_dp) *s++ = '.'; } /* * copy the rest of p, the NUL is NOT copied */ while (*p) *s++ = *p++; if (format != 'f') { char temp[EXPONENT_LENGTH]; /* for exponent conversion */ int t_len; bool_int exponent_is_negative; *s++ = format; /* either e or E */ decimal_point--; if (decimal_point != 0) { p = conv_10((wide_int) decimal_point, FALSE, &exponent_is_negative, &temp[EXPONENT_LENGTH], &t_len); *s++ = exponent_is_negative ? '-' : '+'; /* * Make sure the exponent has at least 2 digits */ if (t_len == 1) *s++ = '0'; while (t_len--) *s++ = *p++; } else { *s++ = '+'; *s++ = '0'; *s++ = '0'; } } *len = s - buf; return (buf); }
/* * Convert a floating point number to a string formats 'f', 'e' or 'E'. * The result is placed in buf, and len denotes the length of the string * The sign is returned in the is_negative argument (and is not placed * in buf). */ static char *conv_fp(register char format, register double num, boolean_e add_dp, int precision, int *is_negative, char *buf, size_t *len) { register char *s = buf; register char *p; int decimal_point; char buf1[NDIG]; if (format == 'f') p = fcvt(num, precision, &decimal_point, is_negative, buf1); else /* either e or E format */ p = ecvt(num, precision + 1, &decimal_point, is_negative, buf1); /* * Check for Infinity and NaN */ if (isalpha(*p)) { *len = strlen(p); memcpy(buf, p, *len + 1); *is_negative = FALSE; return (buf); } if (format == 'f') { if (decimal_point <= 0) { *s++ = '0'; if (precision > 0) { *s++ = '.'; while (decimal_point++ < 0) *s++ = '0'; } else if (add_dp) *s++ = '.'; } else { while (decimal_point-- > 0) *s++ = *p++; if (precision > 0 || add_dp) *s++ = '.'; } } else { *s++ = *p++; if (precision > 0 || add_dp) *s++ = '.'; } /* * copy the rest of p, the NUL is NOT copied */ while (*p) *s++ = *p++; if (format != 'f') { char temp[EXPONENT_LENGTH]; /* for exponent conversion */ size_t t_len; int exponent_is_negative; *s++ = format; /* either e or E */ // // XXX: without the check the routine converts 0.0 to "0.0e-1" // if (num != 0.0) decimal_point--; if (decimal_point != 0) { p = conv_10((int32_t) decimal_point, FALSE, &exponent_is_negative, &temp[EXPONENT_LENGTH], &t_len); *s++ = exponent_is_negative ? '-' : '+'; /* * Make sure the exponent has at least 2 digits */ if (t_len == 1) *s++ = '0'; while (t_len--) *s++ = *p++; } else { *s++ = '+'; *s++ = '0'; *s++ = '0'; } } *len = s - buf; return (buf); }
// Umwandlung eines Double-Wertes entsprechend Format-String // in eine Zeichenkette char *DtoA (double Wert, char *String, const char *Format) { register int Laenge; register int StrLaenge; int NachKomma = 0; int KommaPos; int Sign; char *lpA; char *lpB; // prüfe Parameter if (Format == NULL) Format = DoubleFormat; lpA = (char *) Format + strcspn (Format, "0123456789"); lpB = strchr (Format, '.'); if (lpB) NachKomma = atoi (lpB+1); else { lpB = lpA; NachKomma = 3; } if (lpA <= lpB) Laenge = atoi (lpA); else Laenge = 7; lstrcpy (String, fcvt (Wert, NachKomma, &KommaPos, &Sign)); if (KommaPos <= 0) { StrInsNChr (String, '0', 0, abs (KommaPos) + 1); StrInsNChr (String, '.', 1, 1); } else StrInsNChr (String, '.', KommaPos, 1); if (*(strchr(Format, '%')+1) == '+') { if (!Sign) StrInsNChr (String, '+', 0, 1); } if (Sign) StrInsNChr (String, '-', 0, 1); if (!strchr (Format, '-') && // wenn keine linksbündige Ausgabe (Laenge > (StrLaenge = lstrlen(String)))) StrInsNChr (String, ' ', (String[1] == '0' && (*String == '-' || *String == '+')) ? 1 : 0, Laenge - StrLaenge); if (String[Laenge = (lstrlen(String) -1)] == '.') String[Laenge] = '\0'; // führende Leerzeichen ggf. Löschen char *pStringTmp = '\0'; char *pFirstCh = '\0'; if (*String == ' ') { // 1. gültige Zeichen suchen pFirstCh = String; while (*pFirstCh != '\0' && *pFirstCh == ' ') pFirstCh++; // String umkopieren pStringTmp = String; while (*pFirstCh != '\0') *pStringTmp++ = *pFirstCh++; *pStringTmp = '\0'; // Endekennzeichen setzen } // alle Nullen nach dem Dezimalpunkt löschen pStringTmp = &String [lstrlen (String) - 1]; // auf Letzte Zeichen while (*pStringTmp != '.' && *pStringTmp == '0') *pStringTmp-- = '\0'; // Dezimalpunkt ggf. auch löschen if (*pStringTmp == '.') *pStringTmp = '\0'; return String; }
inline char* _Stl_qfcvtR(long double x, int n, int* pt, int* sign, char* ) { return fcvt(x, n, pt, sign); }
char * dtoa(double d, // IN int mode, // IN int prec, // IN int *expOut, // OUT int *sign, // OUT char **strEnd) // OUT { char *str = NULL; int dec; #if defined(_WIN32) if (2 == mode) { str = malloc(_CVTBUFSIZE); if (str) { if (_ecvt_s(str, _CVTBUFSIZE, d, prec, &dec, sign)) { free(str); str = NULL; } } } else { ASSERT(3 == mode); str = malloc(_CVTBUFSIZE); if (str) { if (_fcvt_s(str, _CVTBUFSIZE, d, prec, &dec, sign)) { free(str); str = NULL; } } /* * When the value is not zero but rounds to zero at prec digits, * the Windows fcvt() sometimes returns the empty string and * a negative dec that goes too far (as in -dec > prec). * For example, converting 0.001 with prec 1 results in * the empty string and dec -2. (See bug 253674.) * * We just clamp dec to -prec when this happens. * * While this may appear to be a safe and good thing to * do in general. It really only works when the result is * all zeros or empty. Since checking for all zeros is * expensive, we only check for empty string, which works * for this bug. */ if (str && *str == '\0' && dec < 0 && dec < -prec) { dec = -prec; } } #else // _WIN32 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; if (2 == mode) { pthread_mutex_lock(&mutex); str = strdup(ecvt(d, prec, &dec, sign)); pthread_mutex_unlock(&mutex); } else { ASSERT(3 == mode); #ifdef __APPLE__ /* * The Mac fcvt() returns "" when prec is 0, so we have to * compensate. See bug 233530. * While it is conceivable that fcvt(round(d), 1) can return * a string that doesn't end in 0, it doesn't seem to happen * in practice (on the Mac). The problematic case that we * want to avoid is a last digit greater than 4, which requires * rounding up, which we don't want to do, which is why we're * doing the rounding on the number instead of after fcvt() * in the first place. * -- edward */ if (prec == 0) { size_t l; pthread_mutex_lock(&mutex); str = strdup(fcvt(round(d), 1, &dec, sign)); pthread_mutex_unlock(&mutex); if (str) { l = strlen(str); ASSERT(l > 0); l--; ASSERT(str[l] == '0'); str[l] = '\0'; } } else #endif // __APPLE__ { pthread_mutex_lock(&mutex); str = strdup(fcvt(d, prec, &dec, sign)); pthread_mutex_unlock(&mutex); } } #endif // _WIN32 if (str) { *strEnd = str + strlen(str); /* strip trailing zeroes */ while ((*strEnd > str) && ('0' == *((*strEnd) - 1))) { (*strEnd)--; } *expOut = dec; } return str; }
void runFailure() { fcvt(anydouble(), anyint(), NULL, NULL); }
void runSuccess() { int d,n; fcvt(anydouble(), anyint(), &d, &n); }
void format (struct obstack *obs, int argc, token_data **argv) { #ifdef HAVE_EFGCVT const char *fmt; /* format control string */ int c; /* a simple character */ char fc; /* format code */ /* Flags. */ char flags; /* 1 iff treating flags */ char ljust; /* left justification */ char mandsign; /* mandatory sign */ char noplus; /* use space if no sign */ char alternate; /* use alternate form */ char zeropad; /* do zero padding */ char plus; /* plus-sign, according to mandatory and noplus */ /* Precision specifiers. */ int width; /* minimum field width */ int prec; /* precision */ int maxch; /* maximum no. of chars to print */ char lflag; /* long flag */ char hflag; /* short flag */ /* Different parts of each specification. */ char sign; /* wanted sign, iff any */ int ppad; /* pre-prefix zero padding */ const char *prefix; /* value prefix */ int lpad; /* zero padding on the left */ register char *s; /* ptr to formatted text */ int rpad; /* zero padding on the rigth*/ const char *suffix; /* value suffix */ /* Buffer and stuff. */ char str[MAXFIELD]; /* buffer for formatted text */ int length; /* length of str */ int padding; /* padding at the left or rigth */ register int i; /* an index */ /* Length of trailing string in str. */ #define LENGTH(s) (&str[MAXFIELD-1] - (s)) #define HAS_SIGN (sign != '\0') fmt = ARG_STR (argc, argv); for (;;) { while ((c = *fmt++) != '%') { if (c == 0) return; obstack_1grow (obs, c); } if (*fmt == '%') { obstack_1grow (obs, '%'); fmt++; continue; } /* Parse flags. */ flags = 1; ljust = mandsign = noplus = alternate = zeropad = 0; do { switch (*fmt) { case '-': /* left justification */ ljust = 1; break; case '+': /* mandatory sign */ mandsign = 1; break; case ' ': /* space instead of positive sign */ noplus = 1; break; case '0': /* zero padding */ zeropad = 1; break; case '#': /* alternate output */ alternate = 1; break; default: flags = 0; break; } } while (flags && fmt++); plus = '\0'; /* what to use as a plus ??? */ if (mandsign) plus = '+'; else if (noplus) plus = ' '; if (ljust) zeropad = 0; /* Minimum field width. */ width = -1; if (*fmt == '*') { width = ARG_INT (argc, argv); fmt++; } else if (isdigit (*fmt)) { width = 0; do { width = width * 10 + *fmt++ - '0'; } while (isdigit (*fmt)); } /* Maximum precision. */ prec = -1; if (*fmt == '.') { if (*(++fmt) == '*') { prec = ARG_INT (argc, argv); ++fmt; } else if (isdigit (*fmt)) { prec = 0; do { prec = prec * 10 + *fmt++ - '0'; } while (isdigit (*fmt)) ; } } /* Length modifiers. */ lflag = (*fmt == 'l'); hflag = (*fmt == 'h'); if (lflag || hflag) fmt++; sign = '\0'; ppad = lpad = rpad = 0; maxch = -1; prefix = suffix = ""; switch (fc = *fmt++) { case '\0': return; case 'c': c = ARG_INT (argc, argv); str[0] = (unsigned char) c; str[1] = '\0'; s = str; break; case 's': s = ARG_STR (argc, argv); maxch = prec; break; case 'd': case 'i': if (lflag) { long val = ARG_LONG (argc, argv); if (val < 0) { val = -val; /* does not work for MINLONG */ sign = '-'; } else sign = plus; s = ulong_to_str ((unsigned long) val, str, 10, digits); } else { int val = ARG_INT (argc, argv); if (hflag) val = (short) val; if (val < 0) { val = -val; /* does not work for MININT */ sign = '-'; } else sign = plus; s = ulong_to_str ((unsigned long) val, str, 10, digits); } if (zeropad) lpad = width - LENGTH (s) - HAS_SIGN; break; case 'o': if (lflag) { unsigned long val = ARG_ULONG (argc, argv); s = ulong_to_str ((unsigned long) val, str, 8, digits); } else { unsigned int val = ARG_UINT (argc, argv); if (hflag) val = (unsigned short) val; s = ulong_to_str ((unsigned long) val, str, 8, digits); } if (alternate) prefix = "0"; if (zeropad) lpad = width - LENGTH (s) - alternate; break; case 'x': case 'X': if (lflag) { unsigned long val = ARG_ULONG (argc, argv); s = ulong_to_str ((unsigned long) val, str, 16, (fc == 'x') ? digits : Digits); } else { unsigned int val = ARG_UINT (argc, argv); if (hflag) val = (unsigned short) val; s = ulong_to_str ((unsigned long) val, str, 16, (fc == 'x') ? digits : Digits); } if (alternate) prefix = (fc == 'X') ? "0X" : "0x"; if (zeropad) lpad = width - LENGTH (s) - 2*alternate; break; case 'u': if (lflag) { unsigned long val = ARG_ULONG (argc, argv); s = ulong_to_str ((unsigned long) val, str, 10, digits); } else { unsigned int val = ARG_UINT (argc, argv); if (hflag) val = (unsigned short) val; s = ulong_to_str ((unsigned long) val, str, 10, digits); } if (zeropad) lpad = width - LENGTH (s); break; case 'e': case 'E': { char *t; int sgn, decpt, exp, n; double val = ARG_DOUBLE (argc, argv); if (prec < 0) prec = 6; t = clr0 (ecvt (val, min (prec + 1, ECVTMAX), &decpt, &sgn)); sign = sgn ? '-' : plus; n = prec; s = str; exp = (t[0] == '0' && t[1] == '\0') ? 0 : decpt - 1; *s++ = *t++; if (n > 0 || alternate) *s++ = '.'; while (*t != '\0' && --n >= 0) *s++ = *t++; *s = '\0'; rpad = n; sgn = 0; if (exp < 0) { exp = -exp; sgn = 1; } t = ulong_to_str ((unsigned long) exp, str, 10, digits); if (exp < 10) *--t = '0'; /* always at least two digits */ *--t = sgn ? '-' : '+'; *--t = fc; if (zeropad) { lpad = width - HAS_SIGN - (s - str) - LENGTH (t); if (rpad > 0) lpad -= rpad; } suffix = t; s = str; } break; case 'f': { const char *t; int sgn, decpt, n; double val = ARG_DOUBLE (argc, argv); if (prec < 0) prec = 6; /* FIXME: For the following line, Dave Anglin reports ``warning: passing arg 1 of `clr0' discards `const' from pointer target type''. I suspect fcvt might be declared as returning const on some systems. Pouah! I should revise this whole module, one of these days... */ t = clr0 (fcvt (val, min (prec, FCVTMAX), &decpt, &sgn)); sign = sgn ? '-' : plus; n = prec; s = str; if (decpt <= 0) { prefix = (n > 0 || alternate) ? "0." : "0"; lpad = min (-decpt, prec); n -= lpad; } else { while (--decpt >= 0) *s++ = *t++; if (n > 0 || alternate) *s++ = '.'; } while (*t && --n >= 0) *s++ = *t++; *s = '\0'; rpad = n; if (zeropad) ppad = width - HAS_SIGN - (prefix[1] ? 2 : 1) - lpad - (s - str) - rpad; s = str; } break; default: continue; } if (lpad < 0) lpad = 0; if (rpad < 0) rpad = 0; if (width < 0) width = 0; i = strlen (s); if (maxch <= 0 || maxch > i) maxch = i; length = (HAS_SIGN + ppad + strlen (prefix) + lpad + maxch + rpad + strlen (suffix)); padding = 0; if (width != 0) { padding = width - length; } if (ljust == 0) /* left padding */ for (i = padding; --i >= 0;) obstack_1grow (obs, ' '); if (HAS_SIGN) /* sign */ obstack_1grow (obs, sign); for (i = ppad; --i >= 0;) /* pre-prefix zero padding */ obstack_1grow (obs, '0'); for (; *prefix; ++prefix) /* prefix */ obstack_1grow (obs, *prefix); for (i = lpad; --i >= 0;) /* left zero padding */ obstack_1grow (obs, '0'); for (i = maxch; --i >= 0; ++s) /* actual text */ obstack_1grow (obs, *s); for (i = rpad; --i >= 0;) /* right zero padding */ obstack_1grow (obs, '0'); for (; *suffix; ++suffix) /* suffix */ obstack_1grow (obs, *suffix); if (ljust != 0) /* right padding */ for (i = padding; --i >= 0;) obstack_1grow (obs, ' '); } #else /* not HAVE_EFGCVT */ char *fmt; /* format control string */ const char *fstart; /* beginning of current format spec */ int c; /* a simple character */ /* Flags. */ char flags; /* 1 iff treating flags */ /* Precision specifiers. */ int width; /* minimum field width */ int prec; /* precision */ char lflag; /* long flag */ char hflag; /* short flag */ /* Buffer and stuff. */ char str[256]; /* buffer for formatted text */ enum {INT, UINT, LONG, ULONG, DOUBLE, STR} datatype; fmt = ARG_STR (argc, argv); for (;;) { while ((c = *fmt++) != '%') { if (c == 0) return; obstack_1grow (obs, c); } fstart = fmt - 1; if (*fmt == '%') { obstack_1grow (obs, '%'); fmt++; continue; } /* Parse flags. */ flags = 1; do { switch (*fmt) { case '-': /* left justification */ case '+': /* mandatory sign */ case ' ': /* space instead of positive sign */ case '0': /* zero padding */ case '#': /* alternate output */ break; default: flags = 0; break; } } while (flags && fmt++); /* Minimum field width. */ width = -1; if (*fmt == '*') { width = ARG_INT (argc, argv); fmt++; } else if (isdigit (*fmt)) { do { fmt++; } while (isdigit (*fmt)); } /* Maximum precision. */ prec = -1; if (*fmt == '.') { if (*(++fmt) == '*') { prec = ARG_INT (argc, argv); ++fmt; } else if (isdigit (*fmt)) { do { fmt++; } while (isdigit (*fmt)); } } /* Length modifiers. */ lflag = (*fmt == 'l'); hflag = (*fmt == 'h'); if (lflag || hflag) fmt++; switch (*fmt++) { case '\0': return; case 'c': datatype = INT; break; case 's': datatype = STR; break; case 'd': case 'i': if (lflag) { datatype = LONG; } else { datatype = INT; } break; case 'o': case 'x': case 'X': case 'u': if (lflag) { datatype = ULONG; } else { datatype = UINT; } break; case 'e': case 'E': case 'f': datatype = DOUBLE; break; default: continue; } c = *fmt; *fmt = '\0'; switch(datatype) { case INT: if (width != -1 && prec != -1) sprintf (str, fstart, width, prec, ARG_INT(argc, argv)); else if (width != -1) sprintf (str, fstart, width, ARG_INT(argc, argv)); else if (prec != -1) sprintf (str, fstart, prec, ARG_INT(argc, argv)); else sprintf (str, fstart, ARG_INT(argc, argv)); break; case UINT: if (width != -1 && prec != -1) sprintf (str, fstart, width, prec, ARG_UINT(argc, argv)); else if (width != -1) sprintf (str, fstart, width, ARG_UINT(argc, argv)); else if (prec != -1) sprintf (str, fstart, prec, ARG_UINT(argc, argv)); else sprintf (str, fstart, ARG_UINT(argc, argv)); break; case LONG: if (width != -1 && prec != -1) sprintf (str, fstart, width, prec, ARG_LONG(argc, argv)); else if (width != -1) sprintf (str, fstart, width, ARG_LONG(argc, argv)); else if (prec != -1) sprintf (str, fstart, prec, ARG_LONG(argc, argv)); else sprintf (str, fstart, ARG_LONG(argc, argv)); break; case ULONG: if (width != -1 && prec != -1) sprintf (str, fstart, width, prec, ARG_ULONG(argc, argv)); else if (width != -1) sprintf (str, fstart, width, ARG_ULONG(argc, argv)); else if (prec != -1) sprintf (str, fstart, prec, ARG_ULONG(argc, argv)); else sprintf (str, fstart, ARG_ULONG(argc, argv)); break; case DOUBLE: if (width != -1 && prec != -1) sprintf (str, fstart, width, prec, ARG_DOUBLE(argc, argv)); else if (width != -1) sprintf (str, fstart, width, ARG_DOUBLE(argc, argv)); else if (prec != -1) sprintf (str, fstart, prec, ARG_DOUBLE(argc, argv)); else sprintf (str, fstart, ARG_DOUBLE(argc, argv)); break; case STR: if (width != -1 && prec != -1) sprintf (str, fstart, width, prec, ARG_STR(argc, argv)); else if (width != -1) sprintf (str, fstart, width, ARG_STR(argc, argv)); else if (prec != -1) sprintf (str, fstart, prec, ARG_STR(argc, argv)); else sprintf (str, fstart, ARG_STR(argc, argv)); break; } *fmt = c; obstack_grow (obs, str, strlen (str)); } #endif /* not HAVE_EFGCVT */ }
//---------- Begin of function Misc::format --------// // // Format a number to a float number to format string // Note : the formated string is right justified // // <double> inNum = the number to be formated // use <double> instead of <float> because // fcvt() only accept <double> // // [int] formatType = 1 - 1,000,000 add thousand seperator // 2 - $1,000,000 add thousand seperator and dollar sign // 3 - 56% add percentage sign % at the end of the number // // return <char*> the pointer to the converted string, the string // is stored in static variable which will be overwritten // in next call. // char* Misc::format(double inNum, int formatType) { enum { MONEY_DEC_PLACE = 2 }; static char outBuf[35]; char *outPtr=outBuf; char *floatStr; int i, intDigit, sign; // intDigit = no. of integer digits floatStr = fcvt( inNum, MONEY_DEC_PLACE, &intDigit, &sign ); #ifdef DEBUG if( intDigit > 29 ) // integer digits can't exceed 29 err.run( "Misc::format(), inNum : %e, formatType : %d", inNum, formatType ); #endif //--------- negetive bracket ------------// if( inNum < 0 ) *outPtr++ = '('; //--------- dollar sign ($) ------------// if( formatType == 2 ) *outPtr++ = '$'; //------- integer number -----------// for( i=intDigit ; i>0 ; i-- ) { if( i%THOUSAND_SEPARATOR_COUNT == 0 && i < intDigit ) *outPtr++ = THOUSAND_SEPARATOR; *outPtr++ = *floatStr++; } if( intDigit <= 0 ) *outPtr++ = '0'; //------- dec. place number -----------// if( inNum > -1000 && inNum < 1000 ) // if the number is less than 1000, add dec. places { // if the number is greater than 1000, truncate any dec. places *outPtr++ = DECIMAL_SEPARATOR; if( *floatStr && intDigit >= 0 ) // e.g. 0.03 --> str:"3", intDight:-1 *outPtr++ = *floatStr++; // 1st dec. place else *outPtr++ = '0'; // add a '0' when intDigit < 0 if( *floatStr ) // 2nd dec. place *outPtr++ = *floatStr++; else *outPtr++ = '0'; } //--------- percent sign (%) ------------// if( formatType == 3 ) *outPtr++ = '%'; //--------- negetive bracket ------------// if( inNum < 0 ) *outPtr++ = ')'; *outPtr++ = '\0'; return outBuf; }
inline char* _Stl_fcvtR(double x, int n, int* pt, int* sign, char* buf) { return fcvt(x, n, pt, sign); }
void mc_fstr(double valeur, int signe, int nbint, int nbfrac,int zeros,char *chaine) /***************************************************************************/ /* Formatage d'une chaine de sortie a partir d'une valeur numerique. */ /***************************************************************************/ /* valeur : valeur numerique a formater */ /* signe : =OK pour ajouter + ou - devant la chaine */ /* =PBB pour ajouter ' ' ou - devant la chaine */ /* =PB pour la valeur absolue */ /* nbint : nombre de chiffres pour la partie entiere */ /* nbfrac : nombre de chiffres pour la partie decimale */ /* zeros : =OK pour laisser les zeros devant sinon (=PB) des espaces */ /***************************************************************************/ { double v,vint,vfrac,cstint,cstfrac; int s,dec,lon,k,ssigne; char chaines[3],chaine1[84],chaine2[84],chaine3[84],chainezero[84]; /*--- test de depassement de chaine ---*/ memset(chaine3,'-',83);chaine3[83]='\0'; lon=0; if (signe==1) { lon+=1; } if (nbfrac>0) { lon+=1; } lon+=(nbint+nbfrac); if (lon>(int)(strlen(chaine3))) { memset(chaine3,'-',strlen(chaine3));chaine3[strlen(chaine3)]='\0'; strcpy(chaine,chaine3); return; } /*--- constantes multiplicatives pour les parties entieres et decimales */ cstint =pow(10,nbint ) ; cstfrac=pow(10,nbfrac) ; /*--- on traite le signe ---*/ s=(int) (mc_sgn(valeur)); if (signe==OK) { if (s>=0) { strcpy(chaines,"+"); } else { strcpy(chaines,"-"); } } else if (signe==PBB) { if (s>=0) { strcpy(chaines," "); } else { strcpy(chaines,"-"); } } else { strcpy(chaines,""); } /*--- on arondit la valeur tronquee ---*/ v=fabs(valeur); vfrac=mc_frac(v*cstfrac); vint=floor(v*cstfrac); if (vfrac>=.5) { v=(vint+1.)/cstfrac; } /*--- on traite la partie entiere ---*/ vint=floor(v); if (vint>=cstint) { vint=cstint-1; } vint+=cstint; strcpy(chaine1,fcvt(vint,nbint+2,&dec,&ssigne)+1); *(chaine1+nbint)='\0'; if ((nbint>1)&&(zeros==PB)) { for (k=1;k<=nbint-1;k++) { if (chaine1[k-1]=='0') { if (signe==PB) { chaine1[k-1]=' '; } else { if (k==1) { chaine1[k-1]=chaines[0]; chaines[0]=' '; } else { chaine1[k-1]=chaine1[k-2]; chaine1[k-2]=' '; } } } else { break; } } } /*--- on traite la partie decimale ---*/ if (nbfrac==0) { strcpy(chaine2,""); } else { vfrac=cstfrac+floor(mc_frac(v)*(cstfrac+.1)); strcpy(chaine2,fcvt(vfrac,nbfrac+2,&dec,&ssigne)+1); memset(chainezero,'0',nbfrac);chainezero[nbfrac]='\0'; strcat(chaine2,chainezero); *(chaine2+nbfrac)='\0'; } /*--- creation de la chaine de sortie formatee ---*/ strcpy(chaine3,chaines); strcat(chaine3,chaine1); if (nbfrac>0) { strcat(chaine3,"."); strcat(chaine3,chaine2); } strcpy(chaine,chaine3); return; }
char * _RTL_FUNC _fcvt(double val, int len, int *decimal, int *sign) { return fcvt(val, len, decimal, sign); }
//start of main void main() { //getch(); initialize(); //initialises graphics mode setcolor(RED); //sets text color red mainscreen(); //draws format for calculator mouse m; //creates mouse object char string[100]; int button,xx,yy,flag=0,index,i; int counter; int matrix[5][3]={{0,1,2},{3,4,5},{6,7,8},{9,10,11},{12,13,14}}; int count=0; //setviewport(70,70,getmaxx()-80,100,1); //clearviewport(); long double num[100],ii=0,rcount=0; drawscreen(); //creates output screen while(1) { counter=150; button=0; m.getmousepos(button,xx,yy); //gets x&y position of mouse ptr if(((button & 1)==1)&&(flag==0)) { for(int k=0;k<5;k++) { for(int x=400,i=0;x<=5*100;x+=50,i++) { if(xx>=x && xx<=x+30 && yy>=counter&&yy<=counter+20) { index=matrix[k][i]; flag=1; //cout<<index; //delay(200); goto end; } } counter+=40; } } end: //(430,350,500,375); if(((button & 1)==1)&&(flag==0)) { if(xx>=430&&xx<=500&&yy>=350&&yy<=375) index=50; flag=1; } switch(index) { case 50: m.getmousepos(button,xx,yy); if(((button & 1)==0) && (flag==1)) { exit(0); } case 0: m.getmousepos(button,xx,yy); if(((button & 1)==0) && (flag==1)) { //setcolor(WHITE); drawscreen(); setcolor(WHITE); string[count]='9'; num[ii]=9; ii++; //outtextxy(getmaxx()-(5*count+200),70,string); count++; string[count]='\0'; outtextxy(getmaxx()-(200+5*count),70,string ); //delay(0); flag=0; } break; case 1: m.getmousepos(button,xx,yy); if(((button & 1)==0) && (flag==1)) { //setcolor(WHITE); drawscreen(); setcolor(WHITE); //outtextxy(getmaxx()-100,70,"8" ); string[count]='8'; count++; string[count]='\0'; num[ii]=8; ii++; outtextxy(getmaxx()-(200+5*count),70,string ); flag=0; } break; case 2: m.getmousepos(button,xx,yy); if(((button & 1)==0) && (flag==1)) { drawscreen(); setcolor(WHITE); //outtextxy(getmaxx()-100,70,"7" ); string[count]='7'; count++; string[count]='\0'; num[ii]=7; ii++; outtextxy(getmaxx()-(200+5*count),70,string ); flag=0; } break; case 3: m.getmousepos(button,xx,yy); if(((button & 1)==0) && (flag==1)) { drawscreen(); setcolor(WHITE); //outtextxy(getmaxx()-100,70,"6" ); string[count]='6'; count++; string[count]='\0'; num[ii]=6; ii++; outtextxy(getmaxx()-(200+5*count),70,string ); flag=0; } break; case 4: m.getmousepos(button,xx,yy); if(((button & 1)==0) && (flag==1)) { drawscreen(); setcolor(WHITE); // outtextxy(getmaxx()-100,70,"5" ); string[count]='5'; count++; string[count]='\0'; num[ii]=5; ii++; outtextxy(getmaxx()-(200+5*count),70,string ); flag=0; } break; case 5: m.getmousepos(button,xx,yy); if(((button & 1)==0) && (flag==1)) { drawscreen(); setcolor(WHITE); //outtextxy(getmaxx()-100,70,"4" ); string[count]='4'; count++; string[count]='\0'; num[ii]=4; ii++; outtextxy(getmaxx()-(200+5*count),70,string ); flag=0; } break; case 6: m.getmousepos(button,xx,yy); if(((button & 1)==0) && (flag==1)) { drawscreen(); setcolor(WHITE); //outtextxy(getmaxx()-100,70,"3" ); string[count]='3'; count++; string[count]='\0'; num[ii]=3; ii++; outtextxy(getmaxx()-(200+5*count),70,string ); flag=0; } break; case 7: m.getmousepos(button,xx,yy); if(((button & 1)==0) && (flag==1)) { drawscreen(); setcolor(WHITE); //+outtextxy(getmaxx()-100,70,"2" ); string[count]='2'; count++; string[count]='\0'; num[ii]=2; ii++; outtextxy(getmaxx()-(200+5*count),70,string ); flag=0; } break; case 8: m.getmousepos(button,xx,yy); if(((button & 1)==0) && (flag==1)) { drawscreen(); setcolor(WHITE); //outtextxy(getmaxx()-100,70,"1" ); string[count]='1'; count++; string[count]='\0'; num[ii]=1; ii++; outtextxy(getmaxx()-(200+5*count),70,string ); flag=0; } break; case 9: m.getmousepos(button,xx,yy); if(((button & 1)==0) && (flag==1)) { drawscreen(); setcolor(WHITE); //outtextxy(getmaxx()-100,70,"0" ); string[count]='0'; count++; string[count]='\0'; num[ii]=0; ii++; outtextxy(getmaxx()-(200+5*count),70,string ); flag=0; } break; case 10: m.getmousepos(button,xx,yy); if(((button & 1)==0) && (flag==1)) { drawscreen(); setcolor(WHITE); //outtextxy(getmaxx()-100,70,"+" ); string[count]='+'; count++; string[count]='\0'; outtextxy(getmaxx()-(200+5*count),70,string ); flag=0; } break; case 11: m.getmousepos(button,xx,yy); if(((button & 1)==0) && (flag==1)) { drawscreen(); setcolor(WHITE); //outtextxy(getmaxx()-100,70,"-" ); string[count]='-'; count++; string[count]='\0'; outtextxy(getmaxx()-(200+5*count),70,string ); flag=0; } break; case 12: m.getmousepos(button,xx,yy); if(((button & 1)==0) && (flag==1)) { clearscreen(); setcolor(WHITE); //string[count]='/'; //count++; //outtextxy(getmaxx()-100,70,"%" ); // string[count]='\0'; // outtextxy(getmaxx()-(200+5*count),70,string ); count=0; flag=0; } break; case 13: m.getmousepos(button,xx,yy); if(((button & 1)==0) && (flag==1)) { drawscreen(); setcolor(WHITE); string[count]='*'; count++; string[count]='\0'; outtextxy(getmaxx()-(200+5*count),70,string ); flag=0; } break; case 14: char s1[100],s2[100]; char * s11,s22; long double value=0; long double n1=0,n2=0; m.getmousepos(button,xx,yy); if(((button & 1)==0) && (flag==1)) { drawscreen(); setcolor(WHITE); for(int k=0;k<count;k++) { if(string[k]=='+'||string[k]=='-'||string[k]=='*'||string[k]=='-') { for(int p=0,q=k-1;p<k;p++,q--) { n1+=(num[p]*(pow(10,q))); } for(p=k,q=(ii-k-1);p<count-1;p++,q--) { n2+=(num[p]*(pow(10,q))); } if(string[k]=='+') { value=(double)(n1+n2); break; } if(string[k]=='-') { value=(double)(n1-n2); break; } if(string[k]=='*') { value=(double)(n1*n2); break; } /* if(string[k]=='cls') { value=(double)(n1/n2); break; }*/ } } int ndig=0,dec,sign; s11 = fcvt(value,ndig, &dec, &sign);//converts a num into string drawscreen(); setcolor(WHITE); outtextxy(getmaxx()-(5*strlen(s11)+200),70,s11); rcount++; flag=0; count=0; ii=0; } break; } } //getch(); restorecrtmode(); //restores textmode }