thats the code i've written so far. now i need to sort it. thanks for your patience.
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define LEN 30
#define LENST 6
int j=0;
char *str[6];
typedef struct
{
int id; //מספר הזהות של הסטודנט
char full_name[LEN]; //שם ושם משפחה
struct
{
unsigned sem_a; //ממוצע הציונים בסמסטר ראשון
unsigned sem_b; //ממוצע הציונים בסמסטר שני
}grades; //משתנה של ציונים מטיפוס של מבנה
}Student;
Student A[]={
{10," SasonSasoniBenSason ",100,100},
{5," Pinokio ",70,90},
{20," JohnRambo ",50,87},
{3,"Elvis",3,77},
{50," JamesBond", 17,1},
{40,"BillGates",91,8}
};
FILE *f;
FILE *to_f;
char first;
char second;
char c,t,g,s;
void write_2_file( char first) //writing the first file. after that im not allowed to touch A struct again.
{
int a=1, i;
f=fopen("one.txt", "w");
if (f==NULL) exit(1);
else
{
printf("the file one has been opened \n\r");
fflush(stdin);
for(i=0;i<LENST;i++)
{
fprintf(f, "%d %s %u %u\n\r", A[i].id, A[i].full_name, A[i].grades.sem_a, A[i].grades.sem_b);
}
if (fclose(f)) exit(1);
else
printf("\nthe file has been closed\n\r");
}
}
void coping(char first, char second) // this function need to copy the first file to a second file sorted with no sort function.
{
f=fopen("one.txt", "r");
to_f=fopen("two.txt", "w");
if ((f== NULL) || (to_f==NULL)) exit(1);
else
{
printf("the files have been opened\n\r");
//for (fscanf(f, "%c", &c); !feof(f); fscanf(f, "%c", &c))
//{
while (!(feof(f)))
{
fgets(str[j],30,f);
//fputs(str,stdout);
j++;
}
//fprintf(to_f, "%c", c);
//fprintf(stdout, "%c",c);
//}
if((fclose(to_f)) || (fclose(f))) exit(1);
else
printf("\n\rthe files had been closed\n\r");
}
}
void main()
{
write_2_file(first);
coping(first,second);
}