ما تصليح وطرق تحسين الكود التالي ؟ علما بان وظيفته مدرجة كملاحظة في بدايته...
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
/*
.
.
.
there is adding recordes while the user want this ,whan we finish,we have to
print all info in records and again recordes the user enter the namne for it after searching
.
.
.*/
/*The general goal of this progect is to make radix sort depending on name
for a group of studentes recordes */
// here, I declare a struct
typedef struct node {
int Id;
char name[50];
float AVG;
struct node *next;
}student;
int main()
{ student *head,
*newn,
*k;
char a,
Title[50],
names[50],
b;
printf("do you want to enter first value? yes press y ,no press any other key\n");
scanf("%s",&a);
if(a='y')
{ printf("if you want to read from file press f, from kayboard press k \n");
scanf("%s",&b);
printf("do you want to enter another new value? yes press y ,no press any other key\n");
scanf("%s",&a);
switch(b)
{
case 'f': FILE *inp;
inp = fopen(Title, "r");
do {
printf("please,Enter the complete path\nfor file you want to read data from it: ");
gets(Title);
}while(!(inp = fopen(Title, "r")));
head=(student*)malloc(sizeof(student));
fscanf(inp, "%d", &head->Id);
fgets(inp, "%s", &head->name);
fscanf(inp, "%f", &head->AVG);
break;
case 'k':printf("Enter the No,Name,AVG");
head=(student*)malloc(sizeof(student ));
scanf(" %d%s%f",&head->Id,&head->name,&head->AVG);
break;
default : printf("error");
break;
}
}
printf("do you want to enter another new value? yes press y ,no press any other key\n");
scanf("%s",&a);
while(a='y')
{ printf("if you want to read from file press f, from kayboard press k \n");
scanf("%s",&b);
switch(b)
{
case 'f': FILE *inp;
inp = fopen(Title, "r");
do {
printf("please,Enter the complete path\nfor file you want to read data from it: ");
gets(Title);
}while(!(inp = fopen(Title, "r")));
newn=(student*)malloc(sizeof(student));
fscanf(inp, "%d", &newn->Id);
fgets(inp, "%s", &newn->name);
fscanf(inp, "%f", &newn->AVG);
newn->next=head;
head=newn;
break;
case 'k': printf("Enter the No,Name,AVG");
newn=(student*)malloc(sizeof(student ));
scanf(" %d%s%f",&newn->Id,&newn->name,&newn->AVG);
newn->next=head;
head=newn;
break;
default : printf("error");
break;
}
printf("do you want to enter another new value? yes press y ,no press any other key\n");
scanf("%s",&a);
}
k=head;
while(k!=NULL)
{
printf(" %d%s%f",&k->Id,&k->name,&k->AVG);
k=k->next;
}
free(k);
// here we will print all data about an name ,the user enter it
printf("Enter the Name to search and give you all information about it");
gets(names);
k=head;
while(k!=NULL&&(strcmp(&k->name,names)==0))
{
printf(" %d%s%f",&k->Id,&k->name,&k->AVG);
k=k->next;
}
return 0;
}وسامحونا يا اعضاء كرام غلبناكم..