#include #include #include #include int main(int argc, char *arvg[]){ char curr_string[500]; double curr_base; int curr_exp; double curr_result_d; char curr_char; strcpy(curr_string, ""); while(1){ curr_char = fgetc(stdin); if(curr_char==EOF){ fprintf(stderr, "ERROR: not a valid file\n"); exit(42); } while( (curr_char < 46) || (curr_char > 57) || (curr_char==47)){ curr_char = fgetc(stdin); if(curr_char==EOF){ fprintf(stderr, "ERROR: not a valid file\n"); exit(42); } } while( ((curr_char > 47) && (curr_char < 58)) || (curr_char == 46) ){//this is the base of the number strncat(curr_string, &curr_char, 1); curr_char = fgetc(stdin); } if(curr_char != 101){//curr_char should now hold the character 'e' fprintf(stderr, "ERROR: not a valid file\n"); exit(42); } //now convert this string to the floating point base curr_base = atof(curr_string); //empty the string so it can hold the exponent strcpy(curr_string, ""); curr_char = fgetc(stdin);//curr_char should now hold the char '+' if(curr_char != 43){ fprintf(stderr, "ERROR: not a valid file (I can't handle anything but positive exponents)\n"); exit(42); } //start building the exponent string curr_char = fgetc(stdin); while( ((curr_char > 47) && (curr_char < 58)) ){//this is the exponent strncat(curr_string, &curr_char, 1); curr_char = fgetc(stdin); } //now convert this string to the integer exponent curr_exp = atoi(curr_string); curr_result_d = curr_base * pow(10, curr_exp); fprintf(stdout, "%.0f", curr_result_d); strcpy(curr_string, ""); if(curr_char == EOF){ fprintf(stderr, "Appear to be at the end of the file\n"); exit(0); } //output white space (tabs, line feeds, etc) until the start of the next number while( ((curr_char < 48) || curr_char > 57)){ fputc(curr_char, stdout); curr_char = fgetc(stdin); if(curr_char == EOF){ fprintf(stderr, "Finished\n"); exit(0); } } strncat(curr_string, &curr_char, 1); } }