PDA

View Full Version : سوال: این کد اشکالاتش چیست وممنون میشوم ان را تصحیح کنید



masoud1372
یک شنبه 24 دی 1391, 22:48 عصر
#include<string.h>
#include<stdio.h>

struct stinfo
{
int studentID;
char name[20];//
char family[30];
char birthyear[10];
char fathername[30];
long int nationalID;
};
struct course_grade//sakhtar baraye nomarat daneshjo
{
int st_ID;
float grade;
}

//farakhanie tavabe shamel:ezafe kardanan daneshjo,dastorol amal,2:hazf daneshjo, 3:broz resani etelaat daneshjo,
//4:jostojoye etelaat va nomarat daneshjo,5:darj nomre jadid,6:darje listi az nomreha baraye 1 dars
//7:hazfe nomre,8:hazfe nomre be sorate listi,9:boroz resanni nomre,10:moshahede vaziate dars
int instruction(void);
void addstudent(FILE * cfptr);
void deletestudent(FILE * cfptr);
void updatestudent(FILE * cfptr);
void search();
void addgrade();
void deletegrade();
void delete1();
void updategrade(void);
void querrybystudentID(void);
void querrybygrade(void);
void main()
{
FILE * cfptr;//tarif pointer be file
int c, request;
char array[15],code[20];//tarife arayeii az noe char bareye esme dars
char courseID[20],*codeptr;
printf("Enter number of course\n");
scanf("%d",&c);
for(int i=0;i<c;++i)// halgheii baraye sakhte file beezaye har dars
{
printf("First enter name and then enter course ID\n");
scanf("%13s%15s",array,&code);//daryefte esme darse va kod an dars
codeptr=&code[0];//enteghale adrese avalin khoneye araye code[] be eshare gare codeptr
strcat(codeptr,".dat");//chasbandane codeptr be file
fopen(codeptr,"w");// baz kardane file baraye har codeptr(be ezaye kod dars)
}
request=instruction();//erja dadane request be tabe instruction
fopen("studentinfo.dat","w");//baz kardane file baraye etelaate daneshjo
if(( cfptr=fopen("studentinfo.dat","rb+"))==NULL)// barresi file bareye tavanaii baz shodan
printf("FILE COULD NOT BE OPENED");
else
{
while( request!=12)
{
switch ( request)//estefade az switch baraye seda zadane tabe morede nazar
{
case 1:
printf("ADDING STUDENTS\n");
addstudent( cfptr);
break;
case 2:
printf("DELETING STUDENT INFORMATION\n");
deletestudent( cfptr);
break;
case 3:
printf("EDITING STUDENT INFORMATION\n");
updatestudent( cfptr);
break;
case 4:
printf("SEARCHING STUDENT INFORMATION AND GRADES");
search();
break;
case 5:
printf("ENTERING NEW GRADES\n");
addgrade();
break;
case 6:
printf("PUTTING LIST OF GRADES FOR A COURSE\n");
addlistgrade();
break;
case 7:
printf("DELETTING A GRADE\n");
deletegrade();
break;
case 8 :/*
deletelistgrade();*/
delete1();
break;
case 9:

printf("UPDATTING GRADES\n");
updategrade();
break;
case 10:
printf("STATUS OF A COURSE ARRANGMENT BY STNUMBER\n");
querrybystudentID();
break;
case 11:
printf("STATUS OF A COURSE ARRANGMENT BY GRADES\n");
querrybygrade();
break;
}
request=instruction();
}
}
printf("\t\tTHE PROGRAM ENDED\n\n");

}
void addstudent(FILE * cfptr)//1:tabe ezafe kardane daneshjo
{
struct stinfo st;
int studentID;
printf("Enter student ID to add\n");
scanf("%d",&studentID);
fseek( cfptr,(studentID-1)*sizeof(struct stinfo),SEEK_SET);
fread(&st,sizeof(struct stinfo),1, cfptr);
printf("\n Please enter name,familyname,birthday year, father name and nationalID:\n");
scanf("%s%s%s%s%d",st.name,st.family,st.birthyear,st.fathername,&st.nationalID);
st.studentID=studentID;
fseek( cfptr,(st.studentID-1)*sizeof(struct stinfo),SEEK_SET);
fwrite(&st,sizeof(struct stinfo),1, cfptr);
}
void deletestudent(FILE * cfptr)
{
struct stinfo st;
struct stinfo blankdata;
int studentID;
printf("Enter student ID to delete\n");
scanf("%d",&studentID);
fseek( cfptr,(studentID-1)*sizeof(struct stinfo),SEEK_SET);
fread(&st,sizeof(struct stinfo),1, cfptr);
if(st.studentID==0)
printf("This person doesnt exist\n");
else
{
fseek( cfptr,(studentID-1)*sizeof(struct stinfo),SEEK_SET);
fwrite(&blankdata,sizeof(struct stinfo),1, cfptr);
printf("Student deletet\n");
}
}
void updatestudent(FILE * cfptr)
{
struct stinfo st;
int studentID;
printf("Enter student ID to update information\n");
scanf("%d",&studentID);
fseek( cfptr,(studentID-1)*sizeof(struct stinfo),SEEK_SET);
fread(&st,sizeof(struct stinfo),1, cfptr);
if(st.studentID==0)
printf("This person does not exist\n");
else
{
fseek( cfptr,(studentID-1)*sizeof(struct stinfo),SEEK_SET);
printf("%2d%2s\n%2s\n%2s\n%2s\n",st.studentID,st.name,st.family,st.birthyear,st.fa thername,st.nationalID);
printf("Enter new information\n");
scanf("%s%s%s%s%d",st.name,st.family,st.birthyear,st.fathername,&st.nationalID);
}

}
int instruction(void)
{
int request;
printf("================================================== =======================\n");
printf("| Enter your request: |\n");
printf("|\tEnter 1 to add a new student |\n");
printf("|\tEnter 2 to delete a student |\n");
printf("|\tEnter 3 to update student information |\n");
printf("|\tEnter 4 to search student information |\n");
printf("|\tEnter 5 to add new grade of student |\n");
printf("|\tEnter 6 to add a list of grades |\n");
printf("|\tEnter 7 to delete a grade of student |\n");
printf("|\tEnter 8 to delete a list of grades |\n");
printf("|\tEnter 9 to update grades |\n");
printf("|\tEnter 10 to see a course information arrangment by student ID |\n");
printf("|\tEnter 11 to see a course information arrangment by grades |\n");
printf("|\tEnter 12 to end |\n");
printf("================================================== =======================\n");

scanf("%d",& request);
return request;
}

void search (){
struct stinfo a;
struct darsinfo d;
long ID;
int sum=0;
float f[20];
float k;
int cou=0;
printf("studentID ra vared konid");
scanf("%ld",&ID);
FILE *efptr;
FILE *dfptr;
FILE *cfptr;
efptr=fopen("studentInfo,dat","rb+");
fread(&a,sizeof(struct students),1,efptr);
while (!feof(efptr)){
if(a.studentID==ID){
printf("%s,%s,%d/%d/%d,%s%ld\n",a.name,a.family,a.birthyear.day,a.birthyear.month ,a.birthyear.year,a.fathername,a.nationalID);
}
}
cfptr=fopen("main file.dat","rb+");
while (!feof(cfptr)){
fread(&s,sizeof(struct dars),1,cfptr);
strcat(s.codedars,".dat");
dfptr=fopen(s.codedars,"rb+");
while(!feof(dfptr)){
fread(&d,sizeof(struct darsinfo),1,dfptr);
if(d.studentID==ID){
printf("%ld%8f\n",s.esmedars,d.nomra);
for(int i=0;i<20;i++){
f[i]=s.nomra;
sum+=f[i];
cou++;
if(f[i]>f[i+1]){
k=f[i];
f[i]=f[i+1];
f[i+1]=k;
}
}
break;
}//end second if
}
printf("mean:%f\nmin:%f\nmax:%f\n",sum/cou,f[0],f[cou-1]);
fclose(dfptr);
}
fclose(cfptr);
fclose(efptr);
}

void addgrade()
{
FILE *cptr;
int a;
struct course_grade grade;
char temp[20],*tempptr;
printf("Enter course ID\n");
scanf("%s",&temp);
tempptr=&temp[0];
strcat(tempptr,".dat");
if((cptr=fopen(tempptr,"rb+"))==NULL)
printf("FILE COULD NOT BE OPENED\n");
else
{
printf("Enter studentID\n");
scanf("%d",&grade.st_ID);
printf("Enter grade\n");
scanf("%f",&grade.grade);
fseek(cptr,(grade.st_ID-1)*sizeof(struct course_grade),SEEK_SET);
fwrite(&grade,sizeof(struct stinfo),1,cptr);
}

fclose(cptr);
}
void addlistgrade()
{
FILE *cptr;
char *tempptr,temp[20];
struct course_grade grade;
int a,i;
printf("Enter course ID\n");
scanf("%s",&temp);
tempptr=&temp[0];
printf("Enter studentID\n");
scanf("%d",&grade.st_ID);
printf("Enter grade\n");
scanf("%f",&grade.grade);
while(grade.st_ID!=0)
{
for(i=0;i<a;++i)
{
strcat(tempptr,".dat");
if((cptr=fopen(tempptr,"rb+"))==NULL)
printf("FILE COULD NOT BE OPENED\n");
else
{
fseek(cptr,(grade.st_ID-1)*sizeof(struct course_grade),SEEK_SET);
fwrite(&grade,sizeof(struct course_grade),1,cptr);
}
}
printf("Enter studentID\n");
scanf("%d",&grade.st_ID);
printf("Enter grade\n");
scanf("%f",&grade.grade);
}
fclose(cptr);
}
void deletegrade()
{
FILE *cptr;
struct course_grade zero={0,0},grade;
char *tempptr,temp[20];
printf("Enter courseID\n");
scanf("%s",&temp);
tempptr=&temp[0];
printf("Enter studentID\n");
scanf("%d",&grade.st_ID);
if((cptr=fopen(tempptr,"rb+"))==NULL)
printf("FILE COULD NOT BE OPENED\n");
else
{
fseek(cptr,(grade.st_ID-1)*sizeof(struct course_grade),SEEK_SET);
fread(&grade,sizeof(struct course_grade),1,cptr);
fwrite(&zero,sizeof(struct stinfo),1,cptr);
}
fclose(cptr);
}
void delete1 (){
long cod;
int b;
struct darsinfo n[100];
struct darsinfo n1={,0.0};
FILE * dfptr;
printf("code dars ra vered konid");
scanf("%ld",&cod);
cfptr=fopen("mainfile.dat","rb");
rewind(cfptr);
while (!feof(cfptr)){
fread(&s,sizeof(struct dars),1,cfptr);
if(s.codedars==cod){
strcat(s.codedars,".dat");
dfptr=fopen(s.codedars,"rb+");
}
}
printf("tedad daneshgooyan ra vared konid");
scanf("%d",&b);
for(int i=0;i<b;i++){
printf("studentID ra vared konid");
scanf("%ld",&n[i].studentID);
rewind(dfptr);
while (!feof(dfptr)){
fread(&s,sizeof(struct darsinfo),1,dfptr);
if(n[i].studentID==s.studentID){
fseek(dfptr,sizeof(struct darsinfo)*(-1),SEEK_CUR);
fwrite(&n1,sizeof(struct darsinfo),1,dfptr);
}//end if
}//end while
}//end for
fclose (dfptr);
}

void updategrade(void)
{
FILE *cptr;
int newgrade;
struct course_grade grade;
char *tempptr,temp[20];
printf("Enter courseID\n");
scanf("%s",&temp);
tempptr=&temp[0];
strcat(tempptr,".dat");
printf("Enter studentID\n");
scanf("%d",&grade.st_ID);
if((cptr=fopen(tempptr,"rb+"))==NULL)
printf("FILE COULD NOT BE OPENED\n");
else
{
fseek(cptr,(grade.st_ID-1)*sizeof(struct course_grade),SEEK_SET);
fread(&grade,sizeof(struct course_grade),1,cptr);
printf("\t%d\t%f\n",grade.st_ID,grade.grade);
printf("Enter new grade\n");
scanf("%f",&grade.grade);
fseek(cptr,(grade.st_ID-1)*sizeof(struct course_grade),SEEK_SET);
fwrite(&grade,sizeof(struct course_grade),1,cptr);
}
fclose(cptr);
}
void querrybystudentID(void)
{
FILE *cptr;
char value[20],*valueptr;
struct course_grade grade;
printf("Enter courseID\n");
scanf("%s",&value);
valueptr=&value[0];
strcat(valueptr,".dat");
if((cptr=fopen(valueptr,"rb+"))==NULL)
printf("FILE COULD NOT BE OPENED\n");
else
{
fread(&grade,sizeof(struct course_grade),1,cptr);
while(!feof(cptr))
{
if(grade.st_ID>0)
{
printf("\t%d\t%f\n",grade.st_ID,grade.grade);
fread(&grade,sizeof(struct course_grade),1,cptr);
}
}
}
fclose(cptr);
}
void querrybygrade(void)
{
FILE *cptr;
FILE *wptr;
char value[20],*valueptr;
struct course_grade grade,temp;
printf("Enter courseID\n");
scanf("%s",&value);
valueptr=&value[0];
strcat(valueptr,".dat");
if((cptr=fopen(valueptr,"rb+"))==NULL)
printf("FILE COULD NOT BE OPENE\n");
else
{
if((wptr=fopen("temp.dat","w"))==NULL)
printf("FILE COULD NOT BE OPEN\n");
else
{
for(long int i=0;i<9999999;++i)
{
fseek(cptr,i*sizeof(struct course_grade),SEEK_SET);
fread(&grade,sizeof(struct course_grade),1,cptr);
temp.grade=grade.st_ID;
temp.st_ID=grade.grade;
fseek(wptr,i*sizeof(struct course_grade),SEEK_SET);
fwrite(&temp,sizeof(struct course_grade),1,wptr);
}
for(long int i=0;i<9999999;++i)
{
fseek(wptr,i*sizeof(struct course_grade),SEEK_SET);
fread(&grade,sizeof(struct course_grade),1,cptr);
if(grade.st_ID>0)
printf("\t%f\t%d\n",grade.grade,grade.st_ID);
}
}
}
}

mahak006
دوشنبه 25 دی 1391, 00:08 صبح
اول اینکه بهتره کدتون رو بره خوانایی بیشتر بین تگ کد قرار بدید .
دوم اینکه بهتر میشه که به همراه کد ، ارور هاتون رو هم بنویسین . چون تو کامپایلر های مختلف و سیستم های مختلف ، ممکنه ارور های متفاوتی بده .


#include<string.h>
#include<stdio.h>

struct stinfo
{
int studentID;
char name[20];//
char family[30];
char birthyear[10];
char fathername[30];
long int nationalID;
};
struct course_grade//sakhtar baraye nomarat daneshjo
{
int st_ID;
float grade;
}

//farakhanie tavabe shamel:ezafe kardanan daneshjo,dastorol amal,2:hazf daneshjo, 3:broz resani etelaat daneshjo,
//4:jostojoye etelaat va nomarat daneshjo,5:darj nomre jadid,6:darje listi az nomreha baraye 1 dars
//7:hazfe nomre,8:hazfe nomre be sorate listi,9:boroz resanni nomre,10:moshahede vaziate dars
int instruction(void);
void addstudent(FILE * cfptr);
void deletestudent(FILE * cfptr);
void updatestudent(FILE * cfptr);
void search();
void addgrade();
void deletegrade();
void delete1();
void updategrade(void);
void querrybystudentID(void);
void querrybygrade(void);
void main()
{
FILE * cfptr;//tarif pointer be file
int c, request;
char array[15],code[20];//tarife arayeii az noe char bareye esme dars
char courseID[20],*codeptr;
printf("Enter number of course\n");
scanf("%d",&c);
for(int i=0;i<c;++i)// halgheii baraye sakhte file beezaye har dars
{
printf("First enter name and then enter course ID\n");
scanf("%13s%15s",array,&code);//daryefte esme darse va kod an dars
codeptr=&code[0];//enteghale adrese avalin khoneye araye code[] be eshare gare codeptr
strcat(codeptr,".dat");//chasbandane codeptr be file
fopen(codeptr,"w");// baz kardane file baraye har codeptr(be ezaye kod dars)
}
request=instruction();//erja dadane request be tabe instruction
fopen("studentinfo.dat","w");//baz kardane file baraye etelaate daneshjo
if(( cfptr=fopen("studentinfo.dat","rb+"))==NULL)// barresi file bareye tavanaii baz shodan
printf("FILE COULD NOT BE OPENED");
else
{
while( request!=12)
{
switch ( request)//estefade az switch baraye seda zadane tabe morede nazar
{
case 1:
printf("ADDING STUDENTS\n");
addstudent( cfptr);
break;
case 2:
printf("DELETING STUDENT INFORMATION\n");
deletestudent( cfptr);
break;
case 3:
printf("EDITING STUDENT INFORMATION\n");
updatestudent( cfptr);
break;
case 4:
printf("SEARCHING STUDENT INFORMATION AND GRADES");
search();
break;
case 5:
printf("ENTERING NEW GRADES\n");
addgrade();
break;
case 6:
printf("PUTTING LIST OF GRADES FOR A COURSE\n");
addlistgrade();
break;
case 7:
printf("DELETTING A GRADE\n");
deletegrade();
break;
case 8 :/*
deletelistgrade();*/
delete1();
break;
case 9:

printf("UPDATTING GRADES\n");
updategrade();
break;
case 10:
printf("STATUS OF A COURSE ARRANGMENT BY STNUMBER\n");
querrybystudentID();
break;
case 11:
printf("STATUS OF A COURSE ARRANGMENT BY GRADES\n");
querrybygrade();
break;
}
request=instruction();
}
}
printf("\t\tTHE PROGRAM ENDED\n\n");

}
void addstudent(FILE * cfptr)//1:tabe ezafe kardane daneshjo
{
struct stinfo st;
int studentID;
printf("Enter student ID to add\n");
scanf("%d",&studentID);
fseek( cfptr,(studentID-1)*sizeof(struct stinfo),SEEK_SET);
fread(&st,sizeof(struct stinfo),1, cfptr);
printf("\n Please enter name,familyname,birthday year, father name and nationalID:\n");
scanf("%s%s%s%s%d",st.name,st.family,st.birthyear, st.fathername,&st.nationalID);
st.studentID=studentID;
fseek( cfptr,(st.studentID-1)*sizeof(struct stinfo),SEEK_SET);
fwrite(&st,sizeof(struct stinfo),1, cfptr);
}
void deletestudent(FILE * cfptr)
{
struct stinfo st;
struct stinfo blankdata;
int studentID;
printf("Enter student ID to delete\n");
scanf("%d",&studentID);
fseek( cfptr,(studentID-1)*sizeof(struct stinfo),SEEK_SET);
fread(&st,sizeof(struct stinfo),1, cfptr);
if(st.studentID==0)
printf("This person doesnt exist\n");
else
{
fseek( cfptr,(studentID-1)*sizeof(struct stinfo),SEEK_SET);
fwrite(&blankdata,sizeof(struct stinfo),1, cfptr);
printf("Student deletet\n");
}
}
void updatestudent(FILE * cfptr)
{
struct stinfo st;
int studentID;
printf("Enter student ID to update information\n");
scanf("%d",&studentID);
fseek( cfptr,(studentID-1)*sizeof(struct stinfo),SEEK_SET);
fread(&st,sizeof(struct stinfo),1, cfptr);
if(st.studentID==0)
printf("This person does not exist\n");
else
{
fseek( cfptr,(studentID-1)*sizeof(struct stinfo),SEEK_SET);
printf("%2d%2s\n%2s\n%2s\n%2s\n",st.studentID,st.n ame,st.family,st.birthyear,st.fathername,st.nation alID);
printf("Enter new information\n");
scanf("%s%s%s%s%d",st.name,st.family,st.birthyear, st.fathername,&st.nationalID);
}

}
int instruction(void)
{
int request;
printf("========================================== ===============================\n");
printf("| Enter your request: |\n");
printf("|\tEnter 1 to add a new student |\n");
printf("|\tEnter 2 to delete a student |\n");
printf("|\tEnter 3 to update student information |\n");
printf("|\tEnter 4 to search student information |\n");
printf("|\tEnter 5 to add new grade of student |\n");
printf("|\tEnter 6 to add a list of grades |\n");
printf("|\tEnter 7 to delete a grade of student |\n");
printf("|\tEnter 8 to delete a list of grades |\n");
printf("|\tEnter 9 to update grades |\n");
printf("|\tEnter 10 to see a course information arrangment by student ID |\n");
printf("|\tEnter 11 to see a course information arrangment by grades |\n");
printf("|\tEnter 12 to end |\n");
printf("========================================== ===============================\n");

scanf("%d",& request);
return request;
}

void search (){
struct stinfo a;
struct darsinfo d;
long ID;
int sum=0;
float f[20];
float k;
int cou=0;
printf("studentID ra vared konid");
scanf("%ld",&ID);
FILE *efptr;
FILE *dfptr;
FILE *cfptr;
efptr=fopen("studentInfo,dat","rb+");
fread(&a,sizeof(struct students),1,efptr);
while (!feof(efptr)){
if(a.studentID==ID){
printf("%s,%s,%d/%d/%d,%s%ld\n",a.name,a.family,a.birthyear.day,a.birt hyear.month,a.birthyear.year,a.fathername,a.nation alID);
}
}
cfptr=fopen("main file.dat","rb+");
while (!feof(cfptr)){
fread(&s,sizeof(struct dars),1,cfptr);
strcat(s.codedars,".dat");
dfptr=fopen(s.codedars,"rb+");
while(!feof(dfptr)){
fread(&d,sizeof(struct darsinfo),1,dfptr);
if(d.studentID==ID){
printf("%ld%8f\n",s.esmedars,d.nomra);
for(int i=0;i<20;i++){
f[i]=s.nomra;
sum+=f[i];
cou++;
if(f[i]>f[i+1]){
k=f[i];
f[i]=f[i+1];
f[i+1]=k;
}
}
break;
}//end second if
}
printf("mean:%f\nmin:%f\nmax:%f\n",sum/cou,f[0],f[cou-1]);
fclose(dfptr);
}
fclose(cfptr);
fclose(efptr);
}

void addgrade()
{
FILE *cptr;
int a;
struct course_grade grade;
char temp[20],*tempptr;
printf("Enter course ID\n");
scanf("%s",&temp);
tempptr=&temp[0];
strcat(tempptr,".dat");
if((cptr=fopen(tempptr,"rb+"))==NULL)
printf("FILE COULD NOT BE OPENED\n");
else
{
printf("Enter studentID\n");
scanf("%d",&grade.st_ID);
printf("Enter grade\n");
scanf("%f",&grade.grade);
fseek(cptr,(grade.st_ID-1)*sizeof(struct course_grade),SEEK_SET);
fwrite(&grade,sizeof(struct stinfo),1,cptr);
}

fclose(cptr);
}
void addlistgrade()
{
FILE *cptr;
char *tempptr,temp[20];
struct course_grade grade;
int a,i;
printf("Enter course ID\n");
scanf("%s",&temp);
tempptr=&temp[0];
printf("Enter studentID\n");
scanf("%d",&grade.st_ID);
printf("Enter grade\n");
scanf("%f",&grade.grade);
while(grade.st_ID!=0)
{
for(i=0;i<a;++i)
{
strcat(tempptr,".dat");
if((cptr=fopen(tempptr,"rb+"))==NULL)
printf("FILE COULD NOT BE OPENED\n");
else
{
fseek(cptr,(grade.st_ID-1)*sizeof(struct course_grade),SEEK_SET);
fwrite(&grade,sizeof(struct course_grade),1,cptr);
}
}
printf("Enter studentID\n");
scanf("%d",&grade.st_ID);
printf("Enter grade\n");
scanf("%f",&grade.grade);
}
fclose(cptr);
}
void deletegrade()
{
FILE *cptr;
struct course_grade zero={0,0},grade;
char *tempptr,temp[20];
printf("Enter courseID\n");
scanf("%s",&temp);
tempptr=&temp[0];
printf("Enter studentID\n");
scanf("%d",&grade.st_ID);
if((cptr=fopen(tempptr,"rb+"))==NULL)
printf("FILE COULD NOT BE OPENED\n");
else
{
fseek(cptr,(grade.st_ID-1)*sizeof(struct course_grade),SEEK_SET);
fread(&grade,sizeof(struct course_grade),1,cptr);
fwrite(&zero,sizeof(struct stinfo),1,cptr);
}
fclose(cptr);
}
void delete1 (){
long cod;
int b;
struct darsinfo n[100];
struct darsinfo n1={,0.0};
FILE * dfptr;
printf("code dars ra vered konid");
scanf("%ld",&cod);
cfptr=fopen("mainfile.dat","rb");
rewind(cfptr);
while (!feof(cfptr)){
fread(&s,sizeof(struct dars),1,cfptr);
if(s.codedars==cod){
strcat(s.codedars,".dat");
dfptr=fopen(s.codedars,"rb+");
}
}
printf("tedad daneshgooyan ra vared konid");
scanf("%d",&b);
for(int i=0;i<b;i++){
printf("studentID ra vared konid");
scanf("%ld",&n[i].studentID);
rewind(dfptr);
while (!feof(dfptr)){
fread(&s,sizeof(struct darsinfo),1,dfptr);
if(n[i].studentID==s.studentID){
fseek(dfptr,sizeof(struct darsinfo)*(-1),SEEK_CUR);
fwrite(&n1,sizeof(struct darsinfo),1,dfptr);
}//end if
}//end while
}//end for
fclose (dfptr);
}

void updategrade(void)
{
FILE *cptr;
int newgrade;
struct course_grade grade;
char *tempptr,temp[20];
printf("Enter courseID\n");
scanf("%s",&temp);
tempptr=&temp[0];
strcat(tempptr,".dat");
printf("Enter studentID\n");
scanf("%d",&grade.st_ID);
if((cptr=fopen(tempptr,"rb+"))==NULL)
printf("FILE COULD NOT BE OPENED\n");
else
{
fseek(cptr,(grade.st_ID-1)*sizeof(struct course_grade),SEEK_SET);
fread(&grade,sizeof(struct course_grade),1,cptr);
printf("\t%d\t%f\n",grade.st_ID,grade.grade);
printf("Enter new grade\n");
scanf("%f",&grade.grade);
fseek(cptr,(grade.st_ID-1)*sizeof(struct course_grade),SEEK_SET);
fwrite(&grade,sizeof(struct course_grade),1,cptr);
}
fclose(cptr);
}
void querrybystudentID(void)
{
FILE *cptr;
char value[20],*valueptr;
struct course_grade grade;
printf("Enter courseID\n");
scanf("%s",&value);
valueptr=&value[0];
strcat(valueptr,".dat");
if((cptr=fopen(valueptr,"rb+"))==NULL)
printf("FILE COULD NOT BE OPENED\n");
else
{
fread(&grade,sizeof(struct course_grade),1,cptr);
while(!feof(cptr))
{
if(grade.st_ID>0)
{
printf("\t%d\t%f\n",grade.st_ID,grade.grade);
fread(&grade,sizeof(struct course_grade),1,cptr);
}
}
}
fclose(cptr);
}
void querrybygrade(void)
{
FILE *cptr;
FILE *wptr;
char value[20],*valueptr;
struct course_grade grade,temp;
printf("Enter courseID\n");
scanf("%s",&value);
valueptr=&value[0];
strcat(valueptr,".dat");
if((cptr=fopen(valueptr,"rb+"))==NULL)
printf("FILE COULD NOT BE OPENE\n");
else
{
if((wptr=fopen("temp.dat","w"))==NULL)
printf("FILE COULD NOT BE OPEN\n");
else
{
for(long int i=0;i<9999999;++i)
{
fseek(cptr,i*sizeof(struct course_grade),SEEK_SET);
fread(&grade,sizeof(struct course_grade),1,cptr);
temp.grade=grade.st_ID;
temp.st_ID=grade.grade;
fseek(wptr,i*sizeof(struct course_grade),SEEK_SET);
fwrite(&temp,sizeof(struct course_grade),1,wptr);
}
for(long int i=0;i<9999999;++i)
{
fseek(wptr,i*sizeof(struct course_grade),SEEK_SET);
fread(&grade,sizeof(struct course_grade),1,cptr);
if(grade.st_ID>0)
printf("\t%f\t%d\n",grade.grade,grade.st_ID);
}
}
}
}

masoud1372
دوشنبه 25 دی 1391, 19:26 عصر
ba campailer visual stadio 2010