Skip to content

Instantly share code, notes, and snippets.

@minhkhoablieu
Created March 31, 2020 17:16
Show Gist options
  • Save minhkhoablieu/1c862bf62c4c4c60219156e34843727a to your computer and use it in GitHub Desktop.
Save minhkhoablieu/1c862bf62c4c4c60219156e34843727a to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
struct Money{
int amount;
char name[100];
};
int main()
{
int n = 9;
struct Money mm[n];
char s[100];
FILE *f = fopen("/Users/gkkk/Desktop/ATM.INP", "r");
int j = 0;
while(!feof(f))
{
fgets(s, 100, f);
char *name = strchr(s, ' ');
memset(mm[j].name, '\0', sizeof(mm[j].name));
strcpy(mm[j].name, name);
char *n = strtok(s, " ");
sscanf(n, "%d", &mm[j].amount);
j++;
}
for(int i = 0; i < n-1; i++)
{
for(int j = 0; j < n - j - 1; j++)
{
if(mm[j].amount > mm[j+1].amount)
{
struct Money temp;
temp = mm[j];
mm[j] = mm[j+1];
mm[j+1] = temp;
}
}
}
for(int i = 0; i < 9; i++)
{
printf("%d %s\n", mm[i].amount, mm[i].name);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment