الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مشكلة بحل سؤال

مغلق
بدأه mamj في 21 أغسطس 2007 · 3 رد · 483 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

انا اقوم بتجميع اسئلة من النت وجعلها ككتاب واحد لطلاب جامعتنا كدعم منا كنادي طلبة لهم

وانا لست قويا بلغة ال c كثيرا

وهناك سؤال وجوابه ولكن المدقق قلي انه جواب خاطيء

ولم اجد له حلا

هلا ساعدتوني

السؤال :

1111122.JPG

وكان الجواب


#include<conio.h>
FILE *infile,*outfile;
struct my_rec{char name[10];
int age;};
typedef struct my_rec test;
void main()
{
int i,j;
double avg,sum=0;
test sample[10];
clrscr();
infile=fopen("inf.dat","r");
outfile=fopen("out.dat","w");
i=0;
while (!feof(infile))

{

fscanf(infile,"%s",&sample.name);
fscanf(infile,"%d",&sample.age);
i++;
}
for(j=0;j<i;j++)
{fprintf(outfile,"%d name= %s\n",j+1,sample[j].name);
sum=sum+sample[j].age;}
avg=sum/(i);
fprintf(outfile,"%f",avg);
}
#include<stdio.h>

ارجو ان ترو ان كان الجواب صحيحا

واذا كان خاطئا

ارجوكم اسعفوني بالجواب

حيث انني اول منتدى واجهنى بعد البحث بجوجل ولا اظنكم سوف تردوني خائبا

وشكرا لكم

بانتظاركم

تم تعديل هذه المشاركة بواسطة Ben_Laiid في 22 أغسطس 2007 في 00:09

#2
#include<stdio.h>
 #include<conio.h>
 FILE *infile,*outfile;
 struct my_rec{char name[10];
			   int id;
			   int salary;};

 typedef struct my_rec test;

 void  main()
		{
		int i,j;
		double avg,sum=0;
		test sample[10];
 //clrscr();
		infile=fopen("c:\\aa.dat","r");
		outfile=fopen("c:\\out.dat","w");
   i=0;
   while (!feof(infile))

 {

   fscanf(infile,"%s",&sample.name);
   fscanf(infile,"%d",&sample.id);
   fscanf(infile,"%d",&sample.salary);
   i++;
   }
   for(j=0;j<i;j++)
   {fprintf(outfile,"%d name= %s id = %d salary = %d tax = %d\n",j+1,
   sample[j].name, sample[j].id, sample[j].salary, (sample[j].salary*17)/100);}  
   }
#3

مشكور اخي على الاجابة

#4

مرحبا

برضو اطلعلي خطأ

بحكيلي

You should be checking if you actually open the file, (fopen returns NULL if it fails), and you should be closing it at the end.

Oh and don't use conio.h.

:(

ممكن تعدلوه

هذا الموضوع مغلق.

مواضيع مشابهة