this problem ask the student name and the grades and keep them in string array. but I have to list all of them in the end of program like this:
Number of students to be entered : 4
1. Student name? Jane
1. Student’s grade? 65
2. Student name? Adam
2. Student’s grade? 85
3. Student name? Jash
3. Student’s grade? 75
4. Student name? Mark
4. Student’s grade? 95
Student List in Name Order
===========================
Adam 75
Jane 85
Jash 95
Tom 65
code:
#include <stdio.h>
#include <conio.h>
#include <string.h>
int mystrcmp(char word[], int counter);
int main()
{
int i, n;
char names[100][20] ={ 10 };
int grades[100] = { 0 };
char tmpName[50] = {40};
char *result;
n = 4;
for( i = 0; i < n; i++ )
{
printf( "Student name? " );
tmpName[0] = 40;
result = _cgets(tmpName);
strcpy(names[i],result);
printf( "Student's grade? " );
scanf ( "%d", &grades[i] );
}
mystrcmp(names,n)
for( i = 0; i < n; i++ )
{
printf( "%s\t%d\n", names[i], grades[i] );
}
return 0;
}
int mystrcmp(char word[][20], int counter)
{
char words[counter][20];
int i,c;
for (i=0; i<counter; i++)
{
while (words[i][c] !=NULL && Words[i+1][c] != NULL)
{
if (words[i][c] > words[i+1][c])
{
// I cant complete the function from here.
I want use buble sort but I cant it. someone can help me for this?