정렬된상태에서 아이디까지 추가해서 출력하고싶은데요;ㅣ;
권애교
아래소스를 실행시키면 제가 coin이라고 지정한 뒤에 숫자만 전부 출력이 되요 오름차순으로.
근데 여기에 앞에 아이디를 같이 연동시켜서 출력하고싶은데 이것좀알려주세요..ㅠㅠㅠ
#includestdio.h
#includestdlib.h
#includestring.h
#includesys/types.h
#includesys/stat.h
#includeunistd.h
#define MAX 100
typedef struct{
char id[20],pwd[20],coin[5];
}GAME;
void swap(int *x, int *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
}
void bubbleSort(int a[], int n)
{
int i,j;
for(i=2;in;i+=3){
for(j=5;jn;j+=3){
if(a[j-3]a[j]){
swap(&a[j-3],&a[j]);
}
}
}
}
void printList(int a[], int n)
{
int i;
for(i=2;in;i+=3){
printf(%d ,a[i]);
printf(\n);
}
}
int main(void){
FILE *fd;
char buffer[1024], *input[100],*input_2;
int i=0;
int j,q[MAX];
int a[MAX],b;
GAME game[MAX];
fd= fopen(tajja.data,r);
while(!(feof(fd)))
{
fscanf(fd, %s, buffer);
}
input_2 = strtok(buffer,:);
while(input_2 != NULL){
input[i]=input_2;
i++;
input_2=strtok(NULL,:);
}
for(j=0;ji;j+=3)
{
strcpy(game[j].id,input[j+0]);
strcpy(game[j].pwd,input[j+1]);
strcpy(game[j].coin,input[j+2]);
printf(☞%s☜===☞%s☜===☞%s☜\n,game[j].id,game[j].pwd,game[j].coin);
}
printf(\n 정렬전\n\n);
int c = 0;
for(j=0;ji;j++){
printf(%s ,input[j]);
q[c] = atoi(input[j]);
c++;
}
printf(\n);
bubbleSort(q,c);
printf(\n정렬후:\n);
printList(q,c);
fclose(fd);
return 0;
}