0

My code works fine for smaller integers, but when it gets over 1 million or so the number changes or goes negative. I am sure this has to do with the range of int, but I tried float and double and all the numbers came out the same...... What is a proper way of reading in an integer (say 5895685684568)?

void numFromFile(char file []){
    txtFile=fopen(file, "r");
    if(txtFile!=NULL){
        int num;  //value in which the int is read in and inserted into the B-tree
        fscanf(txtFile,"%d", &num);
        while(feof(txtFile)==0){  //while not at the end of the file do:
             cout << num << "\n";
            insert(num, root);
            fscanf(txtFile,"%d", &num);
            }
        fclose(txtFile);  // reading in words is done.  The file is closed.
    }
}
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by .:Pudge:.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.