Guest User

Untitled

a guest
May 22nd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include<string.h>
  4.  
  5. int insert(char **tab, char *tekst){
  6. int i=1, p; char*tmp;
  7. if(tab[0]==NULL){
  8. tab[0]=(char*)malloc(strlen(tekst)+1);
  9. strcpy (tab[0], tekst);
  10. return 1;
  11. }
  12. else{
  13. while (tab[i]!=NULL) i++;
  14. tab[i]=(char*)malloc(strlen(tekst)+1);
  15. strcpy (tab[i], tekst);
  16. p=i;
  17. while (strcmp(tekst, tab[i-1])<0){
  18. tmp=tab[i-1];
  19. tab[i-1]=tab[i];
  20. tab[i]=tmp;
  21. i--;
  22. }
  23. return p+1;
  24. }
  25. }
  26.  
  27. void printtab (char **tab, int n){
  28. int i;
  29. printf ("Wczytane stringi: \n");
  30. for (i=0; i<n; i++)
  31. printf("%s", tab[i]);
  32. }
  33.  
  34. int main()
  35. {
  36. char *tab[10], tekst[101], *test;
  37. int i=0, count=0;
  38.  
  39. for(i=0;i<10;i++) tab[i]=0;
  40. i=0;
  41. do{
  42. test=fgets(tekst,100, stdin);
  43. count=insert(tab,tekst);
  44. if (test=="\n") break;
  45. i++;
  46. }while(i<10);
  47. printtab(tab, count);
  48. for(i=0;i<count;i++) free(tab[i]);
  49. system("PAUSE");
  50. return 0;
  51. }
Add Comment
Please, Sign In to add comment