Student database: the user will be asked to input information about students(1-20 students) and the inputs are age,year level,name,course....
the program also will be able to sort the informations ethier by descending or ascending by age or year level... did you understand it? please give me idea how to make this program...

## All 14 Replies

I use class structure for your problem.

``````class student
{
int age;
string year;
string level
string name
string course
};``````

Then you could have a sort method which sorts by either year or level.

thnx... but how can i make the structures elements to be sorted?

is this possible???

``````for(x = 0; x < ARRAY_SIZE; x++)
for(y = 0; y < ARRAY_SIZE-1; y++)
if(student.age[y] > student.age[y+1]) {
holder = student.age[y+1];
student.age[y+1] = student.age[y];
student.age[y] = holder;
}``````

it shows and error of Lvalue required... i don't know how to fix it....

``````#include <stdio.h>
#include <string.h>
#define size 20
struct data{
char name[20];
char course[6];
int age;
int year;
} students[20];
union temporary{
int age;
int year;
char name[20];
char course[6];
} holder;

main()
{
int x,limit;
int input;
do
{
clrscr();
puts("1..insert data");
puts("2..show data");
puts("3..show data in ascending order by age");
puts("4..show data in ascending order by year");
puts("5..show data in descending order by age");
puts("6..show data in descending order by year");
puts("9..exit");
printf("input choice:"); scanf("%d",&input);
switch(input)
{
case 1:
inputdata();
break;
case 2:
showdata();
break;
}
}while(input!=9);

getch();
return 0;
}

inputdata()
{
int limit,x;
printf("Size of structure to make? (1-20)\t");
scanf("%d",&limit);
if(limit<1 || limit>size)
{
printf("Input Invalid!");
}
else
{
limit=limit-1;
printf("\n\n\nAge Year level Course  Name\n");
for(x=0;x<=limit;x++)
{
scanf("%d",&students[x].age);
flushall();
scanf("%d",&students[x].year);
flushall();
gets(students[x].course);
flushall();
gets(students[x].name);
flushall();
}
}
}

showdata()
{
int limit;
int x;
printf("This are the items you inputted!");
printf("\nAge Year level Course  Name\n");
for(x=0;x<size;x++)
{
printf("%d",students[x].age);
printf("\t%s",students[x].year);
printf("\t%s",students[x].course);
printf("\t%s\n",students[x].name);
}
getch();
}
sort_asc_by_age()
{

int x,y;
for(x = 0; x < size; x++)
for(y = 0; y < size; y++)
if(students[y].age > students[y+1].age)
{
holder.age=students[y+1].age;
holder.year=students[y+1].year;
holder.name=students[y+1].name;
holder.course=students[y+1].course;
students[y+1].age=students[y].age;
students[y+1].year=students[y].year;
students[y+1].name=students[y].name;
students[y+1].course=students[y].course;
students[y].age=holder.age;
students[y].name=holder.name;
students[y].year=holder.year;
students[y].course=holder.course;
}
for(x=0;x<size;x++)
{
printf("%d",students[x].age);
printf("\t%s",students[x].year);
printf("\t%s",students[x].course);
printf("\t%s\n",students[x].name);
}
getch();
}
sort_asc_by_year()
{
int x,y;
for(x = 0; x < size; x++)
for(y = 0; y < size-1; y++)
if(students[y].year > students[y+1].age)
{
holder.age=students[y+1].age;
holder.year=students[y+1].year;
holder.name=students[y+1].name;
holder.course=students[y+1].course;
students[y+1].age= students[y].age;
students[y+1].year=students[y].year;
students[y+1].name=students[y].name;
students[y+1].course=students[y].course;
students[y].age=holder.age;
students[y].name=holder.year;
students[y].year=holder.name;
students[y].course=holder.course;
}
for(x=0;x<size;x++)
{
printf("%d",students[x].age);
printf("\t%s",students[x].year);
printf("\t%s",students[x].course);
printf("\t%s\n",students[x].name);
}
getch();
}
sort__desc_by_age()
{

int x,y;
for(x = 0; x < size; x++)
for(y = 0; y < size; y++)
if(students[y].age < students[y+1].age)
{
holder.age=students[y+1].age;
holder.year=students[y+1].year;
holder.name=students[y+1].name;
holder.course=students[y+1].course;
students[y+1].age= students[y].age;
students[y+1].year= students[y].year;
students[y+1].name= students[y].name;
students[y+1].course= students[y].course;
students[y].age =holder.age;
students[y].name =holder.year;
students[y].year =holder.name;
students[y].course=holder.course;
}
for(x=0;x<size;x++)
{
printf("%d",students[x].age);
printf("\t%s",students[x].year);
printf("\t%s",students[x].course);
printf("\t%s\n",students[x].name);
}
getch();
}
sort_desc_by_year()
{

int x,y;
for(x = 0; x < size; x++)
for(y = 0; y < size-1; y++)
if(students[y].year < students[y+1].age)
{
holder.age=students[y+1].age;
holder.year=students[y+1].year;
holder.name=students[y+1].name;
holder.course=students[y+1].course;
students[y+1].age= students[y].age;
students[y+1].year= students[y].year;
students[y+1].name= students[y].name;
students[y+1].course= students[y].course;
students[y].age =holder.age;
students[y].name =holder.year;
students[y].year =holder.name;
students[y].course=holder.course;
}
for(x=0;x<size;x++)
{
printf("%d",students[x].age);
printf("\t%s",students[x].year);
printf("\t%s",students[x].course);
printf("\t%s\n",students[x].name);
}
getch();
}``````

``````PC-lint for C/C++ (NT) Vers. 8.00u, Copyright Gimpel Software 1985-2006

--- Module:   test.c (C)
test.c 25 error [Info 718] Symbol 'clrscr' undeclared, assumed to return int
test.c 25 error [Info 746] call to function 'clrscr()' not made in the presence of a prototype
test.c 37 error [Info 718] Symbol 'inputdata' undeclared, assumed to return int
test.c 37 error [Info 746] call to function 'inputdata()' not made in the presence of a prototype
test.c 40 error [Info 718] Symbol 'showdata' undeclared, assumed to return int
test.c 40 error [Info 746] call to function 'showdata()' not made in the presence of a prototype
test.c 42 error [Info 744] switch statement has no default
test.c 45 error [Info 718] Symbol 'getch' undeclared, assumed to return int
test.c 45 error [Info 746] call to function 'getch()' not made in the presence of a prototype
test.c 47 error [Warning 529] Symbol 'x' (line 21) not subsequently referenced
test.c 47 error [Warning 529] Symbol 'limit' (line 21) not subsequently referenced
test.c 51 error [Info 745] function 'inputdata()' has no explicit type or class, int assumed
test.c 51 error [Warning 532] Return mode of function 'inputdata(void)' inconsistent with line 37
test.c 66 error [Warning 534] Ignoring return value of function 'flushall(void)' (compare with line 299, file c:\progra~1\borland\bcc55\include\stdio.h)
test.c 68 error [Warning 534] Ignoring return value of function 'flushall(void)' (compare with line 299, file c:\progra~1\borland\bcc55\include\stdio.h)
test.c 69 error [Warning 534] Ignoring return value of function 'gets(char *)' (compare with line 179, file c:\progra~1\borland\bcc55\include\stdio.h)
test.c 69 error [Warning 421] Caution -- function 'gets(char *)' is considered dangerous
test.c 70 error [Warning 534] Ignoring return value of function 'flushall(void)' (compare with line 299, file c:\progra~1\borland\bcc55\include\stdio.h)
test.c 71 error [Warning 534] Ignoring return value of function 'gets(char *)' (compare with line 179, file c:\progra~1\borland\bcc55\include\stdio.h)
test.c 71 error [Warning 421] Caution -- function 'gets(char *)' is considered dangerous
test.c 72 error [Warning 534] Ignoring return value of function 'flushall(void)' (compare with line 299, file c:\progra~1\borland\bcc55\include\stdio.h)
test.c 75 error [Warning 533] function 'inputdata(void)' should return a value (see line 50)
test.c 78 error [Info 745] function 'showdata()' has no explicit type or class, int assumed
test.c 78 error [Warning 532] Return mode of function 'showdata(void)' inconsistent with line 40
test.c 86 error [Warning 560] argument no. 2 should be a pointer
test.c 91 error [Warning 533] function 'showdata(void)' should return a value (see line 77)
test.c 91 error [Warning 529] Symbol 'limit' (line 79) not subsequently referenced
test.c 93 error [Info 745] function 'sort_asc_by_age' has no explicit type or class, int assumed
test.c 98 error [Warning 661] Possible access of out-of-bounds pointer (1 beyond end of data) by operator '[' [Reference: file test.c: lines 97, 98]
test.c 100 error [Warning 661] Possible access of out-of-bounds pointer (1 beyond end of data) by operator '[' [Reference: file test.c: lines 97, 100]
test.c 101 error [Warning 661] Possible access of out-of-bounds pointer (1 beyond end of data) by operator '[' [Reference: file test.c: lines 97, 101]
test.c 102 error [Error 64] Type mismatch (assignment) (char [20] = char *)
test.c 102 error [Warning 662] Possible creation of out-of-bounds pointer (1 beyond end of data) by operator '[' [Reference: file test.c: lines 97, 102]
test.c 103 error [Error 64] Type mismatch (assignment) (char [6] = char *)
test.c 103 error [Warning 662] Possible creation of out-of-bounds pointer (1 beyond end of data) by operator '[' [Reference: file test.c: lines 97, 103]
test.c 104 error [Warning 661] Possible access of out-of-bounds pointer (1 beyond end of data) by operator '[' [Reference: file test.c: lines 97, 104]
test.c 105 error [Warning 661] Possible access of out-of-bounds pointer (1 beyond end of data) by operator '[' [Reference: file test.c: lines 97, 105]
test.c 106 error [Error 64] Type mismatch (assignment) (char [20] = char *)
test.c 106 error [Warning 662] Possible creation of out-of-bounds pointer (1 beyond end of data) by operator '[' [Reference: file test.c: lines 97, 106]
test.c 107 error [Error 64] Type mismatch (assignment) (char [6] = char *)
test.c 107 error [Warning 662] Possible creation of out-of-bounds pointer (1 beyond end of data) by operator '[' [Reference: file test.c: lines 97, 107]
test.c 109 error [Error 64] Type mismatch (assignment) (char [20] = char *)
test.c 111 error [Error 64] Type mismatch (assignment) (char [6] = char *)
test.c 116 error [Warning 560] argument no. 2 should be a pointer
test.c 121 error [Warning 533] function 'sort_asc_by_age(void)' should return a value (see line 92)
test.c 123 error [Info 745] function 'sort_asc_by_year' has no explicit type or class, int assumed
test.c 131 error [Error 64] Type mismatch (assignment) (char [20] = char *)
test.c 132 error [Error 64] Type mismatch (assignment) (char [6] = char *)
test.c 135 error [Error 64] Type mismatch (assignment) (char [20] = char *)
test.c 136 error [Error 64] Type mismatch (assignment) (char [6] = char *)
test.c 138 error [Error 64] Type mismatch (assignment) (char [20] = int)
test.c 139 error [Error 64] Type mismatch (assignment) (int = pointer)
test.c 140 error [Error 64] Type mismatch (assignment) (char [6] = char *)
test.c 145 error [Warning 560] argument no. 2 should be a pointer
test.c 150 error [Warning 533] function 'sort_asc_by_year(void)' should return a value (see line 122)
test.c 152 error [Info 745] function 'sort__desc_by_age' has no explicit type or class, int assumed
test.c 157 error [Warning 661] Possible access of out-of-bounds pointer (1 beyond end of data) by operator '[' [Reference: file test.c: lines 156, 157]
test.c 159 error [Warning 661] Possible access of out-of-bounds pointer (1 beyond end of data) by operator '[' [Reference: file test.c: lines 156, 159]
test.c 160 error [Warning 661] Possible access of out-of-bounds pointer (1 beyond end of data) by operator '[' [Reference: file test.c: lines 156, 160]
test.c 161 error [Error 64] Type mismatch (assignment) (char [20] = char *)
test.c 161 error [Warning 662] Possible creation of out-of-bounds pointer (1 beyond end of data) by operator '[' [Reference: file test.c: lines 156, 161]
test.c 162 error [Error 64] Type mismatch (assignment) (char [6] = char *)
test.c 162 error [Warning 662] Possible creation of out-of-bounds pointer (1 beyond end of data) by operator '[' [Reference: file test.c: lines 156, 162]
test.c 163 error [Warning 661] Possible access of out-of-bounds pointer (1 beyond end of data) by operator '[' [Reference: file test.c: lines 156, 163]
test.c 164 error [Warning 661] Possible access of out-of-bounds pointer (1 beyond end of data) by operator '[' [Reference: file test.c: lines 156, 164]
test.c 165 error [Error 64] Type mismatch (assignment) (char [20] = char *)
test.c 165 error [Warning 662] Possible creation of out-of-bounds pointer (1 beyond end of data) by operator '[' [Reference: file test.c: lines 156, 165]
test.c 166 error [Error 64] Type mismatch (assignment) (char [6] = char *)
test.c 166 error [Warning 662] Possible creation of out-of-bounds pointer (1 beyond end of data) by operator '[' [Reference: file test.c: lines 156, 166]
test.c 168 error [Error 64] Type mismatch (assignment) (char [20] = int)
test.c 169 error [Error 64] Type mismatch (assignment) (int = pointer)
test.c 170 error [Error 64] Type mismatch (assignment) (char [6] = char *)
test.c 175 error [Warning 560] argument no. 2 should be a pointer
test.c 180 error [Warning 533] function 'sort__desc_by_age(void)' should return a value (see line 151)
test.c 182 error [Info 745] function 'sort_desc_by_year' has no explicit type or class, int assumed
test.c 191 error [Error 64] Type mismatch (assignment) (char [20] = char *)
test.c 192 error [Error 64] Type mismatch (assignment) (char [6] = char *)
test.c 195 error [Error 64] Type mismatch (assignment) (char [20] = char *)
test.c 196 error [Error 64] Type mismatch (assignment) (char [6] = char *)
test.c 198 error [Error 64] Type mismatch (assignment) (char [20] = int)
test.c 199 error [Error 64] Type mismatch (assignment) (int = pointer)
test.c 200 error [Error 64] Type mismatch (assignment) (char [6] = char *)
test.c 205 error [Warning 560] argument no. 2 should be a pointer
test.c 210 error [Info 783] Line does not end with new-line
test.c 210 error [Warning 533] function 'sort_desc_by_year(void)' should return a value (see line 181)
test.c 211 error [Info 766] Header file 'c:\progra~1\borland\bcc55\include\string.h' not used in module 'test.c'

--- Global Wrap-up

test.c 45 error [Warning 526] Symbol 'getch()' (line 45, file test.c) not defined
test.c 45 error [Warning 628] no argument information provided for function 'getch()' (line 45, file test.c)
test.c 25 error [Warning 526] Symbol 'clrscr()' (line 25, file test.c) not defined
test.c 25 error [Warning 628] no argument information provided for function 'clrscr()' (line 25, file test.c)
test.c 151 error [Info 714] Symbol 'sort__desc_by_age(void)' (line 151, file test.c) not referenced
test.c 92 error [Info 714] Symbol 'sort_asc_by_age(void)' (line 92, file test.c) not referenced
test.c 122 error [Info 714] Symbol 'sort_asc_by_year(void)' (line 122, file test.c) not referenced
test.c 181 error [Info 714] Symbol 'sort_desc_by_year(void)' (line 181, file test.c) not referenced``````

A little raw, but if you fix all of that, most of your troubles will go away.

it shows and error of Lvalue required... i don't know how to fix it...

Use `strcpy` to copy strings.

``````#include <stdio.h>
#include <string.h>

#define size 20

struct data
{
int age;
int year;
char course[6];
char name[20];

} students[20];

struct temporary  //changed to struct?
{
int age;
int year;
char course[6];
char name[20];

} holder;

int main()
{
int x,limit;
int input;
do
{
//clrscr(); non portable avoid if possible
puts("1..insert data");
puts("2..show data");
puts("3..show data in ascending order by age");
puts("4..show data in ascending order by year");
puts("5..show data in descending order by age");
puts("6..show data in descending order by year");
puts("9..exit");
printf("input choice:"); scanf("%d",&input);
switch(input)
{
case 1:
inputdata();
break;
case 2:
showdata();
break;
case 3:

}
}while(input!=9);

getchar(); //getchar better than getch()
//getch is non-portable
return 0;
}

inputdata()
{
int limit,x;
printf("Size of structure to make? (1-20)\t");
scanf("%d",&limit);
if(limit<1 || limit>size)
{
printf("Input Invalid!");
}
else
{
limit=limit-1;
printf("\n\n\nAge Year Course  Name\n");

for(x=0; x<=limit; x++)
{
printf("Age:");
scanf("%d",&students[x].age);
printf("Year:");
scanf("%d",&students[x].year);
printf("Course:");
printf("Name:");
//although scanf is a lesser evil
//for better a better input tutorial in c
//check out dave's tutorial
printf("\nNext entry\n");
}

}
}

showdata()
{
int limit;
int x;
printf("This are the items you inputted!");
printf("\nAge Year level Course  Name\n");
for(x=0;x<size;x++)
{
printf("%d",students[x].age);
printf("\t%d",students[x].year);//changed to %d (it is an integer!)
printf("\t%s",students[x].course);
printf("\t%s\n",students[x].name);
}
getchar(); //getchar better than getch()
}

sort_asc_by_age()
{

int x,y;
for(x = 0; x < size; x++)
for(y = 0; y < size; y++)
if(students[y].age > students[y+1].age)
{
holder.age=students[y+1].age;
holder.year=students[y+1].year;
strcpy(holder.course,students[y+1].course); //changed string copy
strcpy(holder.name,students[y+1].name);// changed

students[y+1].age=students[y].age;
students[y+1].year=students[y].year;
strcpy(students[y+1].name,students[y].name);//changed
strcpy(students[y+1].course,students[y].course);//changed

students[y].age=holder.age;
students[y].year=holder.year;
strcpy(students[y].name,holder.name); //changed
strcpy(students[y].course,holder.course);//changed
}
for(x=0;x<size;x++)
{
printf("%d",students[x].age);
printf("\t%d",students[x].year); //%d
printf("\t%s",students[x].course);
printf("\t%s\n",students[x].name);
}
getch();
}

sort_asc_by_year()
{
int x,y;
for(x = 0; x < size; x++)
for(y = 0; y < size-1; y++)
if(students[y].year > students[y+1].age)
{
holder.age=students[y+1].age;
holder.year=students[y+1].year;
strcpy(holder.course,students[y+1].course); //changed
strcpy(holder.name,students[y+1].name);//changed

students[y+1].age=students[y].age;
students[y+1].year=students[y].year;
strcpy(students[y+1].name,students[y].name);//changed
strcpy(students[y+1].course,students[y].course);//changed

students[y].age=holder.age;
students[y].year=holder.year;
strcpy(students[y].name,holder.name); //changed
strcpy(students[y].course,holder.course);//changed

}
for(x=0;x<size;x++)
{
printf("%d",students[x].age);
printf("\t%d",students[x].year);  //%d
printf("\t%s",students[x].course);
printf("\t%s\n",students[x].name);
}
getchar(); //getchar
}

sort__desc_by_age()
{

int x,y;
for(x = 0; x < size; x++)
for(y = 0; y < size; y++)
if(students[y].age < students[y+1].age)
{
holder.age=students[y+1].age;
holder.year=students[y+1].year;
strcpy(holder.course,students[y+1].course); //changed
strcpy(holder.name,students[y+1].name);//changed

students[y+1].age=students[y].age;
students[y+1].year=students[y].year;
strcpy(students[y+1].name,students[y].name);//changed
strcpy(students[y+1].course,students[y].course);//changed

students[y].age=holder.age;
students[y].year=holder.year;
strcpy(students[y].name,holder.name); //changed
strcpy(students[y].course,holder.course);//changed
}
for(x=0;x<size;x++)
{
printf("%d",students[x].age);
printf("\t%d",students[x].year);  //%d
printf("\t%s",students[x].course);
printf("\t%s\n",students[x].name);
}
getch();
}
sort_desc_by_year()
{

int x,y;
for(x = 0; x < size; x++)
for(y = 0; y < size-1; y++)
if(students[y].year < students[y+1].age)
{
holder.age=students[y+1].age;
holder.year=students[y+1].year;
strcpy(holder.course,students[y+1].course); //changed
strcpy(holder.name,students[y+1].name);//changed

students[y+1].age=students[y].age;
students[y+1].year=students[y].year;
strcpy(students[y+1].name,students[y].name);//changed
strcpy(students[y+1].course,students[y].course);//changed

students[y].age=holder.age;
students[y].year=holder.year;
strcpy(students[y].name,holder.name); //changed
strcpy(students[y].course,holder.course);//changed
}
for(x=0;x<size;x++)
{
printf("%d",students[x].age);
printf("\t%d",students[x].year);  //%d
printf("\t%s",students[x].course);
printf("\t%s\n",students[x].name);
}
getchar(); //getchar()
}``````

please help... i have made it more nicer to output... but the sorting does not sort the structure into ascending or descending... no sorting happens..

``````#include <stdio.h>
#include <string.h>
#include <conio.h>
#define size 20

struct data{
int age;
int year;
char course[6];
char name[20];
} students[20];
struct temporary{
int age;
int year;
char course[6];
char name[20];
} holder;
int main()
{
int x,limit;
int input;
clrscr();
do
{
printf("this will not appear!");
clrscr();
puts("1..insert data");
puts("2..show data in ascending order by age");
puts("3..show data in ascending order by year");
puts("4..show data in descending order by age");
puts("5..show data in descending order by year");
puts("6..exit");
printf("input choice:"); scanf("%d",&input);
switch(input)
{
case 1: inputdata(input);
break;
case 2: sort_asc_by_age(input);
break;
case 3: sort_asc_by_year(input);
break;

case 4: sort_desc_by_age(input);
break;
case 5: sort_desc_by_year(input);
break;

}
}while(input!=6);
printf("Jeffrey polpol!");
getchar();
return 0;
}

inputdata(int input)
{
int limit,x,a,b,c;
clrscr();
printf("Size of data to make? (1-20):\t");
scanf("%d",&limit);
input=limit;
if(limit<1 || limit>size)
{
printf("Input Invalid!");
}
else
{
clrscr();
limit=limit-1;
gotoxy(1,1);
printf("Age   Year    Course      Name");
b=2;
for(x=0; x<=limit; x++)
{
c=1;
a=c;
flushall();
gotoxy(a,b); scanf("%d",&students[x].age);
a=c+6;
c=a;
clreol();
gotoxy(a,b); scanf("%d",&students[x].year);
a=c+8;
c=a;
clreol();
gotoxy(a,b); scanf("%s",students[x].course);
a=c+12;
c=a;
clreol();
gotoxy(a,b); scanf("%s",students[x].name);
b++;
clreol();
gotoxy(a,b); printf("\n Next entry \n");
clreol();
}
}
return input;
}

sort_asc_by_age(int input)
{
int x,y,limit=input;
clrscr();
for(x = 0; x <limit; x++)
for(y = 0; y <limit-1; y++)
if(students[y].age > students[y+1].age)
{
holder.age=students[y+1].age;
holder.year=students[y+1].year;
strcpy(holder.course,students[y+1].course);
strcpy(holder.name,students[y+1].name);
students[y+1].age=students[y].age;
students[y+1].year=students[y].year;
strcpy(students[y+1].name,students[y].name);
strcpy(students[y+1].course,students[y].course);
students[y].age=holder.age;
students[y].year=holder.year;
strcpy(students[y].name,holder.name);
strcpy(students[y].course,holder.course);
}
for(x=0;x<size;x++)
{
printf("%d",students[x].age);
printf("\t%d",students[x].year);
printf("\t%s",students[x].course);
printf("\t%s\n",students[x].name);
}
printf("ayay..");
getch();
}

sort_asc_by_year(int input)
{
int x,y,limit=input;
clrscr();
for(x=0;x<limit; x++)
for(y=0;y<limit-1;y++)
if(students[y].year>students[y+1].age)
{
holder.age=students[y+1].age;
holder.year=students[y+1].year;
strcpy(holder.course,students[y+1].course);
strcpy(holder.name,students[y+1].name);
students[y+1].age=students[y].age;
students[y+1].year=students[y].year;
strcpy(students[y+1].name,students[y].name);
strcpy(students[y+1].course,students[y].course);
students[y].age=holder.age;
students[y].year=holder.year;
strcpy(students[y].name,holder.name);
strcpy(students[y].course,holder.course);
}
for(x=0;x<size;x++)
{
printf("%d",students[x].age);
printf("\t%d",students[x].year);  /*%d*/
printf("\t%s",students[x].course);
printf("\t%s\n",students[x].name);
}
printf("press any to key to menu");
getch();
}

sort_desc_by_age(int input)
{
int x,y,limit=input;
clrscr();
for(x = 0; x < limit; x++)
for(y = 0; y < limit-1; y++)
if(students[y].age < students[y+1].age)
{
holder.age=students[y+1].age;
holder.year=students[y+1].year;
strcpy(holder.course,students[y+1].course);
strcpy(holder.name,students[y+1].name);
students[y+1].age=students[y].age;
students[y+1].year=students[y].year;
strcpy(students[y+1].name,students[y].name);
strcpy(students[y+1].course,students[y].course);
students[y].age=holder.age;
students[y].year=holder.year;
strcpy(students[y].name,holder.name);
strcpy(students[y].course,holder.course);
}
for(x=0;x<size;x++)
{
printf("%d",students[x].age);
printf("\t%d",students[x].year);
printf("\t%s",students[x].course);
printf("\t%s\n",students[x].name);
}
printf("jeffrey asa");
getch();
}

sort_desc_by_year(int input)
{
int x,y,limit=input;
clrscr();
for(x = 0; x < limit; x++)
for(y = 0; y < limit-1; y++)
if(students[y].year < students[y+1].age)
{
holder.age=students[y+1].age;
holder.year=students[y+1].year;
strcpy(holder.course,students[y+1].course);
strcpy(holder.name,students[y+1].name);
students[y+1].age=students[y].age;
students[y+1].year=students[y].year;
strcpy(students[y+1].name,students[y].name);
strcpy(students[y+1].course,students[y].course);
students[y].age=holder.age;
students[y].year=holder.year;
strcpy(students[y].name,holder.name);
strcpy(students[y].course,holder.course);
}
for(x=0;x<size;x++)
{
printf("%d",students[x].age);
printf("\t%d",students[x].year);
printf("\t%s",students[x].course);
printf("\t%s\n",students[x].name);
}
printf("polpol jeffrey");
getch();
}``````

Why I'm not offering much input:

PC-lint for C/C++ (NT) Vers. 8.00u, Copyright Gimpel Software 1985-2006

--- Module: test.c (C)
test.c 36 error [Info 718] Symbol 'inputdata' undeclared, assumed to return int
test.c 36 error [Info 746] call to function 'inputdata()' not made in the presence of a prototype
test.c 38 error [Info 718] Symbol 'sort_asc_by_age' undeclared, assumed to return int
test.c 38 error [Info 746] call to function 'sort_asc_by_age()' not made in the presence of a prototype
test.c 40 error [Info 718] Symbol 'sort_asc_by_year' undeclared, assumed to return int
test.c 40 error [Info 746] call to function 'sort_asc_by_year()' not made in the presence of a prototype
test.c 41 error [Info 725] Expected positive indentation from line 34
test.c 43 error [Info 718] Symbol 'sort_desc_by_age' undeclared, assumed to return int
test.c 43 error [Info 746] call to function 'sort_desc_by_age()' not made in the presence of a prototype
test.c 44 error [Info 725] Expected positive indentation from line 34
test.c 45 error [Info 718] Symbol 'sort_desc_by_year' undeclared, assumed to return int
test.c 45 error [Info 746] call to function 'sort_desc_by_year()' not made in the presence of a prototype
test.c 46 error [Info 725] Expected positive indentation from line 34
test.c 48 error [Info 744] switch statement has no default
test.c 51 error [Warning 534] Ignoring return value of function '_fgetc(FILE *)' (compare with line 294, file c:\progra~1\borland\bcc55\include\stdio.h)
test.c 53 error [Warning 529] Symbol 'x' (line 20) not subsequently referenced
test.c 53 error [Warning 529] Symbol 'limit' (line 20) not subsequently referenced
test.c 56 error [Info 745] function 'inputdata()' has no explicit type or class, int assumed
test.c 56 error [Warning 532] Return mode of function 'inputdata(int)' inconsistent with line 36
test.c 75 error [Warning 525] Negative indentation from line 73
test.c 76 error [Warning 525] Negative indentation from line 73
test.c 77 error [Warning 525] Negative indentation from line 73
test.c 77 error [Warning 534] Ignoring return value of function 'flushall(void)' (compare with line 299, file c:\progra~1\borland\bcc55\include\stdio.h)
test.c 79 error [Warning 525] Negative indentation from line 73
test.c 80 error [Warning 525] Negative indentation from line 73
test.c 81 error [Warning 525] Negative indentation from line 73
test.c 83 error [Warning 525] Negative indentation from line 73
test.c 84 error [Warning 525] Negative indentation from line 73
test.c 85 error [Warning 525] Negative indentation from line 73
test.c 87 error [Warning 525] Negative indentation from line 73
test.c 88 error [Warning 525] Negative indentation from line 73
test.c 89 error [Warning 525] Negative indentation from line 73
test.c 91 error [Warning 525] Negative indentation from line 73
test.c 92 error [Warning 525] Negative indentation from line 73
test.c 95 error [Warning 525] Negative indentation from line 73
test.c 98 error [Warning 527] Unreachable code at token 'printf'
test.c 99 error [Warning 533] function 'inputdata(int)' should return a value (see line 55)
test.c 102 error [Info 745] function 'sort_asc_by_age()' has no explicit type or class, int assumed
test.c 102 error [Warning 532] Return mode of function 'sort_asc_by_age(int)' inconsistent with line 38
test.c 109 error [Warning 525] Negative indentation from line 107
test.c 110 error [Warning 525] Negative indentation from line 107
test.c 111 error [Warning 525] Negative indentation from line 107
test.c 112 error [Warning 525] Negative indentation from line 107
test.c 113 error [Warning 525] Negative indentation from line 107
test.c 114 error [Warning 525] Negative indentation from line 107
test.c 115 error [Warning 525] Negative indentation from line 107
test.c 116 error [Warning 525] Negative indentation from line 107
test.c 117 error [Warning 525] Negative indentation from line 107
test.c 118 error [Warning 525] Negative indentation from line 107
test.c 119 error [Warning 525] Negative indentation from line 107
test.c 120 error [Warning 525] Negative indentation from line 107
test.c 122 error [Warning 539] Did not expect positive indentation from line 105
test.c 124 error [Info 725] Expected positive indentation from line 122
test.c 125 error [Info 725] Expected positive indentation from line 122
test.c 126 error [Info 725] Expected positive indentation from line 122
test.c 127 error [Info 725] Expected positive indentation from line 122
test.c 131 error [Warning 534] Ignoring return value of function 'getch(void)' (compare with line 174, file c:\progra~1\borland\bcc55\include\conio.h)
test.c 132 error [Warning 533] function 'sort_asc_by_age(int)' should return a value (see line 101)
test.c 135 error [Info 745] function 'sort_asc_by_year()' has no explicit type or class, int assumed
test.c 135 error [Warning 532] Return mode of function 'sort_asc_by_year(int)' inconsistent with line 40
test.c 141 error [Warning 525] Negative indentation from line 140
test.c 142 error [Warning 525] Negative indentation from line 140
test.c 143 error [Warning 525] Negative indentation from line 140
test.c 144 error [Warning 525] Negative indentation from line 140
test.c 145 error [Warning 525] Negative indentation from line 140
test.c 146 error [Warning 525] Negative indentation from line 140
test.c 147 error [Warning 525] Negative indentation from line 140
test.c 148 error [Warning 525] Negative indentation from line 140
test.c 149 error [Warning 525] Negative indentation from line 140
test.c 150 error [Warning 525] Negative indentation from line 140
test.c 151 error [Warning 525] Negative indentation from line 140
test.c 152 error [Warning 525] Negative indentation from line 140
test.c 153 error [Warning 525] Negative indentation from line 140
test.c 154 error [Warning 525] Negative indentation from line 140
test.c 162 error [Warning 539] Did not expect positive indentation from line 155
test.c 164 error [Warning 534] Ignoring return value of function 'getch(void)' (compare with line 174, file c:\progra~1\borland\bcc55\include\conio.h)
test.c 165 error [Warning 533] function 'sort_asc_by_year(int)' should return a value (see line 134)
test.c 168 error [Info 745] function 'sort_desc_by_age()' has no explicit type or class, int assumed
test.c 168 error [Warning 532] Return mode of function 'sort_desc_by_age(int)' inconsistent with line 43
test.c 175 error [Warning 525] Negative indentation from line 173
test.c 176 error [Warning 525] Negative indentation from line 173
test.c 177 error [Warning 525] Negative indentation from line 173
test.c 178 error [Warning 525] Negative indentation from line 173
test.c 179 error [Warning 525] Negative indentation from line 173
test.c 180 error [Warning 525] Negative indentation from line 173
test.c 181 error [Warning 525] Negative indentation from line 173
test.c 182 error [Warning 525] Negative indentation from line 173
test.c 183 error [Warning 525] Negative indentation from line 173
test.c 184 error [Warning 525] Negative indentation from line 173
test.c 185 error [Warning 525] Negative indentation from line 173
test.c 186 error [Warning 525] Negative indentation from line 173
test.c 195 error [Warning 539] Did not expect positive indentation from line 188
test.c 197 error [Warning 534] Ignoring return value of function 'getch(void)' (compare with line 174, file c:\progra~1\borland\bcc55\include\conio.h)
test.c 198 error [Warning 533] function 'sort_desc_by_age(int)' should return a value (see line 167)
test.c 201 error [Info 745] function 'sort_desc_by_year()' has no explicit type or class, int assumed
test.c 201 error [Warning 532] Return mode of function 'sort_desc_by_year(int)' inconsistent with line 45
test.c 207 error [Warning 525] Negative indentation from line 206
test.c 209 error [Warning 525] Negative indentation from line 206
test.c 210 error [Warning 525] Negative indentation from line 206
test.c 211 error [Warning 525] Negative indentation from line 206
test.c 212 error [Warning 525] Negative indentation from line 206
test.c 213 error [Warning 525] Negative indentation from line 206
test.c 214 error [Warning 525] Negative indentation from line 206
test.c 215 error [Warning 525] Negative indentation from line 206
test.c 216 error [Warning 525] Negative indentation from line 206
test.c 217 error [Warning 525] Negative indentation from line 206
test.c 218 error [Warning 525] Negative indentation from line 206
test.c 219 error [Warning 525] Negative indentation from line 206
test.c 220 error [Warning 525] Negative indentation from line 206
test.c 228 error [Warning 539] Did not expect positive indentation from line 221
test.c 230 error [Warning 534] Ignoring return value of function 'getch(void)' (compare with line 174, file c:\progra~1\borland\bcc55\include\conio.h)
test.c 231 error [Warning 533] function 'sort_desc_by_year(int)' should return a value (see line 200)
Outputting to file test.lob
c:\progra~1\borland\bcc55\bin\bcc32 -P- -c @MAKE0000.@@@
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
test.c:
Warning W8065 test.c 36: Call to function 'inputdata' with no prototype in function main
Warning W8065 test.c 38: Call to function 'sort_asc_by_age' with no prototype in function main
Warning W8065 test.c 40: Call to function 'sort_asc_by_year' with no prototype in function main
Warning W8065 test.c 43: Call to function 'sort_desc_by_age' with no prototype in function main
Warning W8065 test.c 45: Call to function 'sort_desc_by_year' with no prototype in function main
Warning W8080 test.c 53: 'limit' is declared but never used in function main
Warning W8080 test.c 53: 'x' is declared but never used in function main
Warning W8066 test.c 98: Unreachable code in function inputdata
Warning W8070 test.c 99: Function should return a value in function inputdata
Warning W8004 test.c 88: 'c' is assigned a value that is never used in function inputdata
Warning W8070 test.c 132: Function should return a value in function sort_asc_by_age
Warning W8070 test.c 165: Function should return a value in function sort_asc_by_year
Warning W8070 test.c 198: Function should return a value in function sort_desc_by_age
Warning W8070 test.c 231: Function should return a value in function sort_desc_by_year

:-( im still new to turbo c... i can't understand your post....
can you please make it easier to understand??????

@cezarjont

Get a better compiler

thnx... but what confuses me is how to pass whole structures into functions... :-(

Structures are just like normal variables hence can be passed to the functions in the same way normal variables. The difference between structures and normal variables is that structures are User defined data types.

Consider for example the function which accepts a pointer to a variable and manipulates it.

``````void changeInt (int *ptrToVaribleBeingModified)
{
*ptrToVaribleBeingModified = 10;
}``````

And the same can be done when we pass a reference to structure in the function

``````void changeStructure (MyStructure *ptrToVaribleBeingModified)
{
ptrToVaribleBeingModified->value = 10;
}
// here MyStructure structure has only one field namely int value``````

And in main we have

``````int main (void)
{
int i = 0;
MyStructure structInstance;

changeInt (&i);  // now i becomes 10

changeStructure (&structInstance); // value field becomes 10

getchar ();
return 0;``````

Hope it helped.
Bye.

commented: [Grunt] +1

if you are familiarized with object oriented programming, you can create a class named student with private data such as name, age...
you also must fix each atribute of the object student into an array which you have to order. The use of arrays will make easier the sort.

if you have troubles with the sort you can search for bubble sort which is the most simple way to sort an array.

ex:

``````Student student[10]; /*object of class student*/
/* you must have implemented the class   student before this*/
int  arrayofage[10];

for (int i = 1; i <= 10; i++)
{
arrayofage[i] = student[i].age;
}

/*here you sort the array by a procedure:!: */``````

thnx for all those who help... for all the notes and suggestions... thnx.... and now i'm done... :D and i have come up to this program... :D guided with your help...

``````#include <stdio.h>
#include <string.h>
#include <conio.h>
#define cezarjon 20
struct data{
int age;
int year;
char course[6];
char name[25];
} students[21];
struct secondary{
int age;
int year;
char course[6];
char name[30];
} secondary_storage;
int main()
{
int input;
clrscr();
textcolor(GREEN);
textcolor(WHITE); cscanf("%s",&secondary_storage.name);
sleep(1);
clrscr();
gotoxy(25,10);
textcolor(GREEN); cprintf("Hello %s welcome to my program!",secondary_storage.name);
sleep(3);
textcolor(GREEN);
clrscr();
gotoxy(25,10); cprintf("Welcome to cezar's Program!");
sleep(2);
clrscr();
input_data_on_storage();
do
{
printf("para dili mo error ang clear screen");
clrscr();
gotoxy(25,8);
textcolor(GREEN);
cprintf(" 1_ _show data in ascending order by age");
gotoxy(25,9);
textcolor(GREEN);
cprintf(" 2_ _show data in ascending order by year");
gotoxy(25,10);
textcolor(GREEN);
cprintf(" 3_ _show data in descending order by age");
gotoxy(25,11);
textcolor(GREEN);
cprintf(" 4_ _show data in descending order by year");
gotoxy(25,12);
textcolor(GREEN);
cprintf(" 5_ _exit");
gotoxy(25,7);
textcolor(GREEN);
cprintf("Input choice:");
scanf("%d",&input);
if(input== 1 || 2 || 3 || 4)
{
switch(input)
{
case 1: sorting_data_in_ascending_by_age();
break;
case 2: sorting_data_in_ascending_by_year();
break;

case 3: sorting_data_in_descending_by_age();
break;
case 4: sorting_data_in_descending_by_year();
break;
}
}
else
{
textcolor(YELLOW);
cprintf("Input not allowed!");
}
} while(input!=5);
clrscr();
gotoxy(25,10);
textcolor(GREEN);
cprintf("Good Bye!");
getchar();
return 0;
}

input_data_on_storage()
{
int x,limit,a,b,c,d,e,f,input;
clrscr();
gotoxy(25,10);
textcolor(YELLOW);
cprintf("Please dont input space! Thank you! ^_^");
sleep(3);
clrscr();
gotoxy(25,1); textcolor(GREEN);
cprintf("STUDENT INFORMATION");
gotoxy(15,2);
textcolor(GREEN);
cprintf("Name               Age    Year     Course");
textcolor(YELLOW);
gotoxy(15,3);
cprintf("(string)           (int)  (int)    (string)");
f=1;
e=4;
b=4;
for(x=0;x<cezarjon;x++)
{
d=1;
c=15;
a=c;
gotoxy(d,e);
textcolor(GREEN);
cprintf("Input No. %d:",f);
flushall();
gotoxy(a,b);
textcolor(WHITE); cscanf("%s",&students[x].name);
a=c+19;
c=a;
gotoxy(a,b);
textcolor(WHITE); cscanf("%d",&students[x].age);
a=c+7;
c=a;
gotoxy(a,b);
textcolor(WHITE); cscanf("%d",&students[x].year);
a=c+9;
c=a;
gotoxy(a,b);
textcolor(WHITE); cscanf("%s",&students[x].course);
b++;
textcolor(YELLOW);
cprintf("\nNEXT ENTRY");
clreol();
e++;
f++;
}
textcolor(219);
}

sorting_data_in_ascending_by_age()
{
int x,y,a,b,c,d,e,f;
clrscr();
for(x=0;x<cezarjon;x++)
for(y=0;y<cezarjon-1;y++)
if(students[y].age > students[y+1].age)
{
secondary_storage.age=students[y+1].age;
secondary_storage.year=students[y+1].year;
strcpy(secondary_storage.course,students[y+1].course);
strcpy(secondary_storage.name,students[y+1].name);
students[y+1].age=students[y].age;
students[y+1].year=students[y].year;
strcpy(students[y+1].name,students[y].name);
strcpy(students[y+1].course,students[y].course);
students[y].age=secondary_storage.age;
students[y].year=secondary_storage.year;
strcpy(students[y].name,secondary_storage.name);
strcpy(students[y].course,secondary_storage.course);
}
gotoxy(6,1);  textcolor(GREEN);
cprintf("Age   Year    Course      Name");
b=3;
d=2;
f=1;
e=3;
for(x=0;x<cezarjon;x++)
{
c=6;
a=c;
gotoxy(d,e);
textcolor(YELLOW);
cprintf("%d.",f);
gotoxy(a,b);
cprintf("%d",students[x].age);
a=c+6;
c=a;
gotoxy(a,b);
cprintf("%d",students[x].year);
a=c+8;
c=a;
e++;
gotoxy(a,b);
cprintf("%s",students[x].course);
a=c+12;
c=a;
gotoxy(a,b);
cprintf("%s",students[x].name);
b++;
f++;
}
textcolor(219);
cprintf("\n\nPress any key to see menu");
getch();
}

sorting_data_in_ascending_by_year()
{
int x,y,a,b,c,d,e,f;
clrscr();
for(x=0;x<cezarjon;x++)
for(y=0;y<cezarjon-1;y++)
if(students[y].year>students[y+1].year)
{
secondary_storage.age=students[y+1].age;
secondary_storage.year=students[y+1].year;
strcpy(secondary_storage.course,students[y+1].course);
strcpy(secondary_storage.name,students[y+1].name);
students[y+1].age=students[y].age;
students[y+1].year=students[y].year;
strcpy(students[y+1].name,students[y].name);
strcpy(students[y+1].course,students[y].course);
students[y].age=secondary_storage.age;
students[y].year=secondary_storage.year;
strcpy(students[y].name,secondary_storage.name);
strcpy(students[y].course,secondary_storage.course);
}
gotoxy(6,1);
textcolor(GREEN); cprintf("Age   Year    Course      Name");
b=3;
d=2;
f=1;
e=3;
for(x=0;x<cezarjon;x++)
{
c=6;
a=c;
gotoxy(d,e);
textcolor(YELLOW);
cprintf("%d.",f);
gotoxy(a,b);
cprintf("%d",students[x].age);
a=c+6;
c=a;
gotoxy(a,b);
cprintf("%d",students[x].year);
a=c+8;
c=a;
e++;
gotoxy(a,b);
cprintf("%s",students[x].course);
a=c+12;
c=a;
gotoxy(a,b);
cprintf("%s",students[x].name);
b++;
f++;
}
textcolor(219);
getch();
}

sorting_data_in_descending_by_age()
{
int x,y,a,b,c,d,e,f;
clrscr();
for(x=0;x<cezarjon;x++)
for(y=0;y<cezarjon-1;y++)
if(students[y].age > students[y+1].age)
{
secondary_storage.age=students[y+1].age;
secondary_storage.year=students[y+1].year;
strcpy(secondary_storage.course,students[y+1].course);
strcpy(secondary_storage.name,students[y+1].name);
students[y+1].age=students[y].age;
students[y+1].year=students[y].year;
strcpy(students[y+1].name,students[y].name);
strcpy(students[y+1].course,students[y].course);
students[y].age=secondary_storage.age;
students[y].year=secondary_storage.year;
strcpy(students[y].name,secondary_storage.name);
strcpy(students[y].course,secondary_storage.course);
}
gotoxy(6,1);
textcolor(GREEN);
cprintf("Age   Year    Course      Name");
b=3;
d=2;
f=1;
e=3;
for(x=cezarjon-1;x>=0;x--)
{
c=6;
a=c;
gotoxy(d,e);
textcolor(YELLOW);
cprintf("%d.",f);
gotoxy(a,b);
textcolor(GREEN);
cprintf("%d",students[x].age);
a=c+6;
c=a;
gotoxy(a,b);
textcolor(GREEN);
cprintf("%d",students[x].year);
a=c+8;
c=a;
e++;
gotoxy(a,b);
textcolor(GREEN);
cprintf("%s",students[x].course);
a=c+12;
c=a;
gotoxy(a,b);
textcolor(GREEN);
cprintf("%s",students[x].name);
b++;
f++;
}textcolor(219);
getch();
}

sorting_data_in_descending_by_year()
{

int x,y,a,b,c,d,e,f;
clrscr();
for(x=0;x<cezarjon;x++)
for(y=0;y<cezarjon-1;y++)
if(students[y].year>students[y+1].year)
{
secondary_storage.age=students[y+1].age;
secondary_storage.year=students[y+1].year;
strcpy(secondary_storage.course,students[y+1].course);
strcpy(secondary_storage.name,students[y+1].name);
students[y+1].age=students[y].age;
students[y+1].year=students[y].year;
strcpy(students[y+1].name,students[y].name);
strcpy(students[y+1].course,students[y].course);
students[y].age=secondary_storage.age;
students[y].year=secondary_storage.year;
strcpy(students[y].name,secondary_storage.name);
strcpy(students[y].course,secondary_storage.course);
}
gotoxy(6,1);
textcolor(GREEN);
cprintf("Age   Year    Course      Name");
b=3;
d=2;
f=1;
e=3;
for(x=cezarjon-1;x>=0;x--)
{     c=6;
a=c;
gotoxy(d,e);
textcolor(YELLOW);
cprintf("%d.",f);
gotoxy(a,b);
textcolor(GREEN);
cprintf("%d",students[x].age);
a=c+6;
c=a;
gotoxy(a,b);
textcolor(GREEN);
cprintf("%d",students[x].year);
a=c+8;
c=a;
e++;
gotoxy(a,b);
textcolor(GREEN);
cprintf("%s",students[x].course);
a=c+12;
c=a;
gotoxy(a,b);
textcolor(GREEN);
cprintf("%s",students[x].name);
b++;
f++;
}
textcolor(219);