d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Previous Question Simplified
Add Reply New Topic New Poll
Member
Posts: 3,210
Joined: Aug 21 2010
Gold: 152.00
Dec 13 2012 09:51am
Code


float *text[2];

float[0] = malloc(sizeof(float));

float[1] = malloc(sizeof(float));

fscanf(fp, "%f", text[0]);

printf("Number: %.2f\n", text[0]);



How can I read a float from a file into this pointer array
Member
Posts: 3,546
Joined: Jan 28 2006
Gold: 1,584.00
Dec 13 2012 10:56am
There are some possibilities:

Pointer to an array:

Code
float *text;
text = (float*)malloc(2*sizeof(float));
fscanf(fp, "%f", &text[0]);
printf("Number: %.2f\n", text[0]);



Array of pointers:

Code
float *text[2];
text[0] = (float*)malloc(sizeof(float));
text[1] = (float*)malloc(sizeof(float));
fscanf(fp, "%f", text[0]);
printf("Number: %.2f\n", *text[0]);



Normal array:

Code
float text[2];
fscanf(fp, "%f", &text[0]);
printf("Number: %.2f\n", text[0]);


This post was edited by dipdipdip on Dec 13 2012 10:56am
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll