| | |
Input from file issues
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2009
Posts: 8
Reputation:
Solved Threads: 0
I don't get what is happening here. I used this exact code for another algorithm and it works but here i only get large negative numbers for an input, what gives?
My output is:
floatArray[0] is -107374176.000000
floatArray[1] is -107374176.000000
floatArray[2] is -107374176.000000
floatArray[3] is -107374176.000000
floatArray[4] is -107374176.000000
floatArray[5] is -107374176.000000
floatArray[0] is -107374176.000000
floatArray[1] is -107374176.000000
floatArray[2] is -107374176.000000
floatArray[3] is -107374176.000000
floatArray[4] is -107374176.000000
floatArray[5] is -107374176.000000
My output is:
floatArray[0] is -107374176.000000
floatArray[1] is -107374176.000000
floatArray[2] is -107374176.000000
floatArray[3] is -107374176.000000
floatArray[4] is -107374176.000000
floatArray[5] is -107374176.000000
floatArray[0] is -107374176.000000
floatArray[1] is -107374176.000000
floatArray[2] is -107374176.000000
floatArray[3] is -107374176.000000
floatArray[4] is -107374176.000000
floatArray[5] is -107374176.000000
c++ Syntax (Toggle Plain Text)
int main(int argc, char *argv[]) { /* Extract value for # of elements in array */ int d; sscanf (argv[2], "%d", &d); /* Create Input and Output Streams */ ifstream fin; ofstream fout; /* Open Input Stream */ fin.open("numlist.dat"); /* Tests to ensure files opened */ if(fin.fail()) { cerr << "Input did not open\n"; exit(2); } /* Construct New Array */ float *floatArray= new float[d]; /* Put numbers from list into array */ float item; // printf("Put Numbers from list into array\n"); for (j=0; j<d;j++) { fin >> item; // printf("item is %f\n", item); floatArray[j]=item; printf("floatArray[%d] is %f\n", j, floatArray[j]); } /* Call to HEapSort */ HeapSort(floatArray, len); /* Display Array After Sort */ for (j=0; j<d;j++) { printf("floatArray[%d] is %f\n", j, floatArray[j]); } /* Close file for Reading */ fin.close(); /* Open Output Stream */ fout.open("numlist.dat.srt"); /* Tests to ensure files opened */ if(fout.fail()) { cerr << "Input did not open\n"; exit(2); } /* Write Output */ for (i=0;i<d;i++) { fout << floatArray[i] << endl; } /* Close File */ fout.close(); getchar(); }
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: Draw Rectangle Using Loops
- Next Thread: GPA Calculator
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion count database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive return sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






