Nobody has yet answered your question. The answer is no. Its impossible to tell the file that you want to pass an integer or float. Thats because files are made up of a bunch of characters (stream) and only bunches of characters (streams). This means when you read a character array (stream): "24" from a file, you must convert it to an integer which is easy using the "atoi" function. The character 0 has a numerical value 48. Which means everytime you read the number 7 from a file its not stored as an integer. What youre looking at is the character seven, which has the numerical value of 47 7=54. And thats actually what the atoi function does. It does this conversion. Heck, heres the function right here!:
1 2 3 4 5 6 7 8 9
|
/* atoi: convert s to integer */
int atoi(char s[])
{
int i, n;
n = 0;
for (i = 0; s[i] >= '0' && s[i] <= '9'; i)
n = 10 * n (s[i] - '0');
return n;
}
|
Thus if you want a text file to store integers, make it a char save it to that file. Then you have to read it as char (because once again files are one big char array). If you read it as character 10, pass this value to the atoi function (character to integer) or even character to float or whatever (other conversions exist). Then only can you apply arithmetic to these numbers. However I ask myself. why do you need to pass integers to your file? Because of age? Why does age have to be an integer? Remember, you store "age" just because someone must see it on the screen. And if someone is 24 years old, why not just save it as two character array. A 2 and a 4.
On a sidenote I use the C method:
I dont know just how unorthodox this method is but it works for me :D. Highlight the entire excel spreadsheet and paste it in a txt document and save it in a directory. Youll notice its columns are actually seperated by a "tab" and its rows seperated by new line characters n. Take note of that because once you do its easy to manipulate.
To "use" this text, load it into an appropriately sized character array.
Open the file for reading:
1 2 3 4 5 6 7 8
|
FILE * pFile;
int i;
char text_file[36000];
pFile = fopen ("the_name_of_the_text_file_you_want.txt","r");
int getc(FILE *pFile);
for(i=0;text[i]!=EOF;i )
text[i]=getc(pFile);
|
Now your text file is loaded into a character array.