Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include<string.h>
- int insert(char **tab, char *tekst){
- int i=1, p; char*tmp;
- if(tab[0]==NULL){
- tab[0]=(char*)malloc(strlen(tekst)+1);
- strcpy (tab[0], tekst);
- return 1;
- }
- else{
- while (tab[i]!=NULL) i++;
- tab[i]=(char*)malloc(strlen(tekst)+1);
- strcpy (tab[i], tekst);
- p=i;
- while (strcmp(tekst, tab[i-1])<0){
- tmp=tab[i-1];
- tab[i-1]=tab[i];
- tab[i]=tmp;
- i--;
- }
- return p+1;
- }
- }
- void printtab (char **tab, int n){
- int i;
- printf ("Wczytane stringi: \n");
- for (i=0; i<n; i++)
- printf("%s", tab[i]);
- }
- int main()
- {
- char *tab[10], tekst[101], *test;
- int i=0, count=0;
- for(i=0;i<10;i++) tab[i]=0;
- i=0;
- do{
- test=fgets(tekst,100, stdin);
- count=insert(tab,tekst);
- if (test=="\n") break;
- i++;
- }while(i<10);
- printtab(tab, count);
- for(i=0;i<count;i++) free(tab[i]);
- system("PAUSE");
- return 0;
- }
Add Comment
Please, Sign In to add comment