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

مشكلة في الكود, ممكن رايكم

مغلق
بدأه mohamad alaa في 21 مارس 2006 · 1 رد · 530 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

ارجو مساعدتي في اكتشاف اخطاء البرنامج :( :unsure:

#include <stdio.h>
  #include <conio.h>
  #include <stdlib.h>
  #include <ctype.h>
  #define null 0

typedef struct students{
struct students *last;
int id;
char name[10];
float gpa;
struct students *link;
}student;


typedef struct course {struct course *last;
int id;
int grade;
float group;
struct course *link;
}courses;


void main(){
student *k,*kk,*kkk;
courses *coa,*cob,*p,*pt,*ptr;
student *createstudent();
courses *createcourse();
void displaystudent(  student*);
void displaycourse(  courses*);
int ch ,no;
 do{
 clrscr();
 printf ("\n\n\n\t\t PROGRAM TO PERFORM VARIOUS OPREATION");
 printf("\n\n\n\t\t*******MENU FOR OPERATION**********");
 printf("\n\t\t 1. create student list");
 printf("\n\t\t 2. display student list");
 printf("\n\t\t 3.create student course A");
 printf("\n\t\t 4. display student course A ");
 printf("\n\t\t 5.create student course B");
  printf("\n\t\t6. display student course B ");
  scanf("%d",&ch);
  switch(ch)
  {
  case 1:
  k=createstudent();
  getch ();
  break;
  case 2:
  displaystudent(k);break;
  case 3:
  coa=createcourse();break;
  case 4:
  displaycourse(coa);break;
  case 5:
  cob=createcourse();break;
  case 6:
  displaycourse(cob);break;
  }while(ch!=-99);





student * createstudent() {
student *head,*temp,*newn;
int no,i;
up:clrscr();
printf("\n\t enter number of node:");
scanf("%d",&no);
if( no==-99)
goto up;
 for(i=1;i< no;i++)
        {
         newn=(student*)malloc(sizeof(student));
        newn->link=0;
        newn->last=0;
        head=newn;
        printf("\nENTER THE INFORMATION OF STUDENT");
        scanf("%d %s %f",&newn->id,&newn->name,&newn->gpa);
        if(i==1){
        head=temp=newn; }
        else
        temp= newn;
        newn=(student*)malloc(sizeof(student));
        newn->link=null;
        newn->last=temp;
       temp->link=newn;}fflush(stdin);
        free(newn);
        temp->link=null;
        return (head);}

   courses * createcourse ();
 {courses head,temp,newn;
int n=sizeof(courses),no,i;
up:clrscr();
printf("\n\t enter number of node:");
scanf("%d",&no);
if( no==-99)
goto up;
 for(i=1;i< no;i++)
        {
      newn =(courses)malloc(sizeof(n));
        newn->link=null;
        newn->last=null;
        head=newn;
        printf("\nENTER THE INFORMATION OF STUDENT");
        scanf("%d %d %f",(&newn->id),(&newn->group),(&newn->gpa();
        if(i==1){
        head=temp=newn; }
        else
        temp= newn;
        newn=(courses*)malloc(sizeof(n));
        newn->link=null;
        newn->last=temp;
        temp->link=newn;}fflush(stdin);
        free(newn);
        temp->link=null;
        return (head);}

تم تعديل هذه المشاركة بواسطة Xacker في 21 مارس 2006 في 18:23

#2

تم تعديل الكود لهذا الشكل

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>
#define null 0
typedef struct students {
  struct students *last;
  int id;
  char name[10];
  float gpa;
  struct students *link;
}student;

typedef struct course {
  struct course *last;
  int id;
  int grade;
  float group;
  struct course *link;
}courses;

student * createstudent(void);
courses * createcourse(void);
void displaystudent(student*);
void displaycourse(courses*);

void main() {
  student *k;
  courses *coa,*cob;
  int ch;
  do {
//    clrscr();
    printf ("\n\n\n\t\t PROGRAM TO PERFORM VARIOUS OPREATION");
    printf("\n\n\n\t\t*******MENU FOR OPERATION**********");
    printf("\n\t\t 1. create student list");
    printf("\n\t\t 2. display student list");
    printf("\n\t\t 3.create student course A");
    printf("\n\t\t 4. display student course A ");
    printf("\n\t\t 5.create student course B");
    printf("\n\t\t6. display student course B ");
    scanf("%d", &ch);
    switch(ch) {
      case '1':
        k = createstudent();
        getch(); break;
      case '2':
        displaystudent(k); break;
      case '3':
        coa = createcourse(); break;
      case '4':
        displaycourse(coa); break;
      case '5':
        cob = createcourse(); break;
      case '6':
        displaycourse(cob); break;
    }
  }while(ch != - 99);
}
student * createstudent() {
  student *head,*temp,*newn;
  int no,i;
up:
//  clrscr();
  printf("\n\t enter number of node:");
  scanf("%d", &no);
  if(no == - 99)
    goto up;
  for(i = 1; i < no; i++) {
    newn = (student*)malloc(sizeof(student));
    newn->link = 0;
    newn->last = 0;
    head = newn;
    printf("\nENTER THE INFORMATION OF STUDENT");
    scanf("%d %s %f", &newn->id, &newn->name, &newn->gpa);
    if(i==1)
      head = temp = newn;
    else
      temp = newn;
    newn = (student*) malloc(sizeof(student));
    newn->link = null;
    newn->last = temp;
    temp->link = newn;
  }
  fflush(stdin);
  free(newn);
  temp->link = null;
  return head;
}

courses * createcourse () {
  courses *head, *temp, * newn;
  int n = sizeof(courses), no, i;
up:
//  clrscr();
  printf("\n\t enter number of node:");
  scanf("%d",&no);
  if( no == - 99)
    goto up;
  for(i = 1; i < no; i++) {
    newn = (courses *) malloc(sizeof(n));
    newn->link = null;
    newn->last = null;
    head = newn;
    printf("\nENTER THE INFORMATION OF STUDENT");
    scanf("%d %d %f", &newn->id, &newn->grade, &newn->group);
    if(i == 1)
      head = temp = newn;
    else
      temp = newn;
    newn = (courses*) malloc(sizeof(n));
    newn->link = null;
    newn->last = temp;
    temp->link = newn;
  }
  fflush(stdin);
  free(newn);
  temp->link = null;
  return head;
}

باقي اضافة الكود الخاص بالدالتين

void displaystudent(student*);
void displaycourse(courses*);

تم تعديل هذه المشاركة بواسطة Asm4all في 22 مارس 2006 في 07:45

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

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