Public feed #533309

Anonymous

public text v1 · immutable
Raw Edit
·published 2007-06-03 12:20 UTC
rendered paste body
#include <sys/types.h> 
#include <stdio.h>
#include <dirent.h> 
    
typedef struct _lista{ 
        
       char nazwa[40]; 
        
       struct _lista *nast, *pop; 
        
       }lista; 
  
lista *dodaj(lista *lista1,char *fnazwa) 
   {       
          lista *nowy; 
          nowy=malloc(sizeof(lista)); 
          
          if(lista1==NULL) 
          { 
               strcpy(nowy->nazwa,fnazwa); 
               //nowy->nazwa[20]=fnazwa[20]; 
               nowy->nast=NULL; 
               nowy->pop=NULL; 
               lista1=nowy; 
                
               return lista1; 
                
       } 
           else 
           { 
               strcpy(nowy->nazwa,fnazwa); 
               lista1->pop=nowy; 
               nowy->nast=lista1; 
               nowy->pop=NULL; 
               lista1=nowy; 
                
               return lista1; 
       } 
        
   } 
    
/*-----------------------wyswietla liste---------------------------*/ 
void wyswietl1(lista *lista1) 
{ 
   lista *tym; 
    
   tym=lista1; 
   while(tym!=NULL) 
   { 
       printf("%s\n",tym->nazwa); 
       tym=tym->nast; 
        
   } 
    
} 




int main (void)                         
{ 
 DIR *dp; 
 struct dirent *ep; 
 lista *lista1=NULL; 
 char fnazwa[20]; 
    
 dp = opendir ("C://"); 
 if (dp != NULL) 
 { 
    
   while (ep = readdir (dp)) 
   { 
       //strcpy(fnazwa,ep->d_name); 
       lista1=dodaj(lista1,ep->d_name);   
   } 

(void) closedir (dp); 
 } 
  
 else 
 { 
   perror ("Nie mozna otworzyc katalogu"); 
 } 
 wyswietl1(lista1); 
  
 getchar(); 
}