Page 1 of 2
File read/write
Posted:
Tue Feb 21, 2006 5:57 am
by Joshua Worth
how do you you use the file read/write functions?
Posted:
Tue Feb 21, 2006 6:25 pm
by makslane
Do you mean saveVars?
Posted:
Tue Feb 21, 2006 9:05 pm
by Joshua Worth
No, I mean fopen+fclose etc.
Posted:
Wed Feb 22, 2006 2:31 pm
by makslane
You can see example in standard C programs.
Look at google for fopen, fwrite, ...
Posted:
Sat Feb 25, 2006 10:57 am
by Joshua Worth
can you give me a straight foward way to open a text file, read each line, turn them into integers instead of strings, and put each into an array.
Posted:
Sat Feb 25, 2006 11:07 am
by makslane
What's the file format?
Something like this?
10
12
30
45
Posted:
Sat Feb 25, 2006 10:09 pm
by Joshua Worth
yes
Posted:
Mon Feb 27, 2006 9:03 pm
by Joshua Worth
Please give me an answer quickly, i havent got long
Posted:
Tue Feb 28, 2006 7:55 pm
by makslane
Put this code in the Global Code editor:
- Code: Select all
int readLines(char *fileName, int max, long *array)
{
int i = 0;
FILE *fp = fopen(fileName, "r");
if(fp)
{
while(fscanf(fp, "%d", &array[i]) > 0)
{
i++;
}
fclose(fp);
}
//Number of read lines
return i;
}
If you are using a array of integer (with 100 elements), you can use this code in the Script Editor:
- Code: Select all
readLines("file.txt", 100, myArray);
Download the sample here:
http://game-editor.com/examples/readlines.zip
Posted:
Wed Mar 01, 2006 6:44 am
by Joshua Worth
Posted:
Wed Mar 08, 2006 6:24 am
by Joshua Worth
How can i make it read into a string instead?
Posted:
Wed Mar 08, 2006 12:31 pm
by makslane
Create a array of strings and use the code:
fscanf(fp, "%s", array[i]) //Without &
Posted:
Wed Mar 08, 2006 8:55 pm
by Joshua Worth
I have to change the long *array at the top dont i?
Posted:
Thu Mar 09, 2006 2:13 am
by makslane
yes
Posted:
Fri Mar 10, 2006 5:27 am
by Joshua Worth
what to?