Hi,
I have written a structure of 5 stocks allowing user to enter info on 5 stocks, the code below is the function I have attempted to write a function using bubblesort to sort the stock names inputed in alphabetical order from A to Z. Did I do it right? And how to get the program to print out the result off the sort (i.e., the names after it gone thru the bubblesort?)
Code:
void sortStock(struct Stock s[], int n)
{
int i, j, k;
char t[9];
for(i=0; i<n-1; i++)
for(j=0; j<n-1; j++)
if (strcmp(s[j].stock_name, s[j+1].stock_name)>0)
{
strcpy(t, s[j+1].stock_name);
strcpy(s[j].stock_name, s[j+1].stock_name);
strcpy(s[j+1].stock_name, t);
}
// for(int k = 0; k<n; k++)
// printf("%s", s[SIZE]);
// printf("\n\n");
}