Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MAIN
- #include <cstdlib>
- #include <cstdio>
- #include <cstring>
- #include "funcs.h"
- int compar(const void*, const void*);
- using namespace std;
- int main(int argc, char** argv) {
- char **nom;
- int numDat;
- leer(nom,numDat);
- qsort(nom,numDat,sizeof(char*),compar);
- imp(nom,numDat);
- return 0;
- }
- int compar(const void* d1, const void* d2){
- char **nom1 = (char**)d1;
- char **nom2 = (char**)d2;
- return strcmp(*nom1,*nom2);
- }
- // HEADER
- #ifndef FUNCS_H
- #define FUNCS_H
- void leer(char **&, int &);
- void imp(char **, int);
- #endif /* FUNCS_H */
- // IMPLEMENTACION
- #include <cstdlib>
- #include <cstdio>
- #include <cstring>
- #include "funcs.h"
- void leer(char **&nom, int &numDat){
- char *buff[50], aux[50]; numDat = 0;
- while (gets(aux) != NULL){
- buff[numDat] = new char[strlen(aux)+1];
- strcpy(buff[numDat],aux);
- numDat++;
- }
- nom = new char*[numDat];
- for (int i = 0; i<numDat; i++)
- nom[i] = buff[i];
- }
- void imp(char **nom, int numDat){
- for (int i = 0; i<numDat; i++)
- printf("%-10s \n",nom[i]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement