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.
    }
}

Thanks. Yeah I ended up using %lg for the double

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.