-
How to print the data from my array?
over 8 years ago
-
over 5 years ago
pass address of the pointer object in the fwrite function,it will give u correct output -
-
over 6 years ago
#include<stdio.h>
int main()
{
int arr[5],i;
for(i=0;i<5;i++)
{
scanf("%d",&arr[i]);
}
for(i=0;i<5;i++)
{
printf("%d",arr[i]);
} -
-
over 6 years ago
Syntax :
int fread(void *Buffer,int Size,int Count,FILE *ptr); u need to pass the address of the structure, not the direct pointer. u need to declare structure variable. node: void *Buffer receives address of the variable, not the pointer. That's why ur getting incorrect output.
-
-
over 8 years ago
Hi pietroamaral,
Actually I am more comfortable with fprintf than fwrite, please have a look on the below code. It worked for me.#include <stdio.h> #include <stdlib.h> #include <string.h> struct dados { char matr[50]; char ele[50]; float ela[50]; float final[50]; int freq[50]; float recu[50]; }; int main() { struct dados *object = NULL; object = (struct dados *)malloc(sizeof(struct dados)); strcpy(object->matr,"diario"); FILE *fp = NULL; fp = fopen("dataTest.txt","w"); if (fp != NULL) { fprintf(fp,"%s",object->matr); } close(fp); return 0; }
-
4 Answer(s)