![]() |
| ||
| Need help on my assignment !!! - about file streams :(( I got this code here, i wonder why it doesnt put in the file "in.dat" in the same folder.
2. Im trying to do this(as said in the assignment): - Type in the experimental data in a text file and save the file as “in.dat”. - In the data entry part, use the fscanf() function to read the data from “ïn.dat" file. It is very important that you store the data in a suitable array ( data[N][2] for example). Make sure that all the array's elements are set to zero before you use the array. This is what i need to put in the file: 0 -0.545 Thanks for helps guys :( I really need it >< |
| ||
| Re: Need help on my assignment !!! - about file streams :(( you opened the file for reading, not writeing. |
| ||
| Re: Need help on my assignment !!! - about file streams :(( Thanx i realized that. The reason im doing that to input in the file is to get the pointer position so that i can read from the file and get the data in to my arrays. Is there any easier way to do that ? |
| ||
| Re: Need help on my assignment !!! - about file streams :(( Open it for reading and writing? |
| ||
| Re: Need help on my assignment !!! - about file streams :(( Wat i did is i write the data in first, then open it for reading the data in the file to the array. ;( Trying to figure out, any help ? >< |
| ||
| Re: Need help on my assignment !!! - about file streams :(( Just open it for reading and writing. Write to it, read from it. What's the problem? You can find how fopen works for reading and writing on numerous C reference sites. |
| ||
| Re: Need help on my assignment !!! - about file streams :(( Nah thats alright dw about it i fixed the writing reading problem. This is another approach. Index.txt is the file that has the data above. #include <stdio.h> With this code, if M = N then it works (providing the data is in square matrix, which is not suitable for me. My goal: Input the data from index.txt to the array a[M][N] with M is row and N is collumn. index.txt 0.000000 -0.545000 |
| ||
| Re: Need help on my assignment !!! - about file streams :(( Instead of using the loops to initialize the array, you can also do it when the array is declared, like this: float a[M][M] = {0};
The above will initialize all elements of the array to 0. |
| ||
| Re: Need help on my assignment !!! - about file streams :(( I still dont understand how my code doesnt work for 21*2 Matrix. , it doesnt read from the file and put in the matrix. Thx for the short way of initializing arrays :p |
| ||
| Re: Need help on my assignment !!! - about file streams :(( Two things: This is a typo: FILE *ifp, ;Remove the comma: FILE *ifp ; And you might want to read this about void main The rest of the code looks fine to me. What doesn't work? |
| All times are GMT -4. The time now is 10:24 pm. |
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC