Created
June 5, 2015 17:21
-
-
Save toanalien/67c7ce0142ead044eff8 to your computer and use it in GitHub Desktop.
sort an array using pointer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <conio.h> | |
#include <string.h> | |
#define MAXLEN 10 | |
#define MAXNUM 5 | |
int main() | |
{ | |
char cname[MAXNUM][MAXLEN]; | |
char *cptr[MAXNUM]; | |
char *ctemp; | |
int *j; | |
int i, ij, icount = 0; | |
while (icount <MAXNUM) | |
{ | |
printf("Nhap vao ten nguoi thu %d: ", icount + 1); | |
gets(cname[icount]); | |
cptr[icount++] = cname[icount]; | |
} | |
for (i = 0; i < icount - 1; i++) | |
for (ij = i + 1; ij < icount; ij++) | |
if (strcmp(cptr[i], cptr[ij]) > 0) | |
{ | |
ctemp = cptr[i]; | |
cptr[i] = cptr[ij]; | |
cptr[ij] = ctemp; | |
} | |
printf("Danh sachs sau khi da sap xep:\n"); | |
for (i = 0; i < icount; i++) | |
printf("Ten nguoi thu %d: %s \n", i + 1, cptr[i]); | |
getch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment