السلام عليكم ورحمة الله وبركاته ..
حيا الله أعضاء هذا المنتدى الفاضل .. والرائع ..
أتمنى مساعدتي في هذا الكود ..
الكود اريده أن يقرأ من ملف فيه أعداد .. كلما مرة يقرا اربعة اعداد فقط ..
ويضيفها في linked list .. ويطبعها على الشاشة ..
يقول لي الاخطاء صفر .. بس لما اعمل debug ما يطلع شيء على الشاشة ..
وشكرا ..
#include<fstream>
#include<iostream>
using namespace std;
struct pass //structure of passenger
{
int ID; //passenger number
int src; //source floor
int dst; //destination floor
int time; //the time of request
int wtime; //waiting time
pass *next;
};
void printAll(pass *head);
void prepend(int ID,int time,int src,int dst, pass *&head);
int main()
{
ifstream inp("test.txt");
int i,n,x;
i=1;
inp>>x;
while (x != -1)
{
inp >>x;
i++;
}
n= (i)/4;
return n;
int j=0;
while (j <= n)
{
int d,y,z,w;
inp>>x>>y>>z>>w;
pass *listpass = NULL;
prepend(d,y,z,w,listpass);
printAll(listpass);
cout << endl << endl;
j++;
}
}
void prepend(int ID,int time,int src,int dst, pass *&head)
{
pass *newp = new pass;
newp->ID = ID;
newp->time = time;
newp->src = src;
newp->dst = dst;
newp->next = head;
head = newp;
}
void printAll(pass *head)
{
pass *N = head;
while(N != NULL)
{
cout << "[ " << N->ID << " ]"<< "[ " << N->time << " ]"<< "[ " << N->src << " ]"<< "[ " << N->dst << " ]";
cout << "--->"<< endl;
N = N->next;
}
cout << "*";
}