thanks for the replies .. I have a solution that appears to do what I want so far ..
Code:
#include<stdio.h>
//prototyping my structure added second variable and will need more later
struct foo{
int array[5];
double array2[5];
};
int main(){
//creating a foo structure bar and assigning a pointer to it
struct foo bar;
struct foo *p;
p = &bar;
//creating a file pointer
FILE *fp;
//counter
int c;
//giving values to array elements in structure
for(c = 0; c < 5; c++){
p->array[c] = c;
p->array2[c] = c - 1.2;//cheap way of making a double
}
//pinting out values .. checking
for(c = 0; c < 5; c++){
printf(" c = %i i = %i\n",c,p->array[c]);
printf(" c = %i f = %f\n",c,p->array2[c]);
}
//opening a file so I can write values to it
fp = fopen("foobar.txt","wb");
for(c = 0; c < 5; c++){
fprintf(fp,"%i\n",p->array[c]);
fprintf(fp,"%f\n",p->array2[c]);
}
fclose(fp);
return;
}
//yay!! thanks for the help
trying CommonTaters suggestion
Code:
#include<stdio.h>
//prototyping my structure
struct foo{
int array[5];
};
int main(){
//creating a foo structure bar and assigning a pointer to it
struct foo bar;
struct foo *p;
p = &bar;
//creating a file pointer
FILE *fp;
//counter
int c;
//giving values to array elements in structure
for(c = 0; c < 5; c++){
p->array[c] = c;
}
//pinting out values .. checking
for(c = 0; c < 5; c++){
printf(" c = %i i = %i\n",c,p->array[c]);
}
//opening a file so I can write values to it
fp = fopen("foobar.txt","wb");
fwrite(foo,sizeof(foo),1,fp);
fclose(fp);
return;
}
I get an error
cc pointer.c
pointer.c: In function ‘main’:
pointer.c:28:10: error: ‘foo’ undeclared (first use in this function)
pointer.c:28:10: note: each undeclared identifier is reported only once for each function it appears in
so not sure how to proceed using fwrite atm ..
thanks again for the help so far .. if anyones interested in showing me my errors with the fwrite feel free .. al.