I have a problem if FILEs
:confused: :confused: :confused:
hello ther i am a new one here :)
I have a problem with files :
That i can't read and write to a file when the wreten item is
int or float (when i write ther comes charecters whit out meaning).
and when i write char it is very G:) :) D ...
please solve my problem :o :o
ofcours in C,,,
thank you,,,,
thank you Prelude for answering
hello thank you for answering :)
and thos os the code useing fwrite.
i hope that you can help my....
PHP Code:
#include<stdio.h>
//-------------------------------------
struct data
{
int id;
int gpa;
};
//-------------------------------------
//-------------------------------------
void readrec(struct data *r)
{
printf("\n Enter the ID No: ");
scanf("%d",&r->id);
printf("\n Enter the GPA: ");
scanf("%d",&r->gpa);
}
//-------------------------------------
main()
{
FILE *fp;
struct data r;
int ch=0;
fp=fopen("struct.txt","a+");
printf("\n Enter (1)to write. (0)to EXIT.");
scanf("%d",&ch);
while(ch!=0)
{
readrec(&r);
fwrite(&r,sizeof(struct data),1,fp);
printf("\n Enter (1)to write. (0)to EXIT.");
scanf("%d",&ch);
}
}
2 know (I opend the file a,a+,w,w+,wb)but it did't work :(