0

Instead of putting in 40 for the for loop i want to get the length of the array which is where i want to store the information from the file. Would I use strlen or sizeof? Overall, how would i take in the information from the file and then store it in the array to get the size of the array in the for loop where the 40 would have been. Thank you. Also I am assuming to use strlen, correct?

Int40 *loadPlainText(char *fname){//declare function
        int i; //for eventual for loop
        char c;//declare character c
        Int40 *Point=createInt40(); //call the create function because it returns a pointer to the int40 struct that holds an array filled with 0s
        //something has to catch the value that the function returns. thats why its equal to  structure
        FILE* ifp = fopen(inputFilename, "r");//opens thew file in read mode
        int arr[40];//declare an array
        for(i=0;i<=40;i++){//for loop
            fscanf(ifp, "%c", &arr[i]);//read file into an array
            Point->digits[i]=c;
        }//end for loop
        return Point;//return the pointer
    }//end function
  • If you want to know how big is the file take a look at this: https://stackoverflow.com/questions/8236/how-do-you-determine-the-size-of-a-file-in-c – Fabio_MO Mar 15 '18 at 13:53
  • 1
    BTW: Comments such as `//declare character c` are useless, they only add clutter. For statements such as `a = b + c;` you don't add comments such as `// add a and b and put result into c`, do you? – Jabberwocky Mar 15 '18 at 14:03

0 Answers0