コード例 #1
0
ファイル: lib02.c プロジェクト: Josephkzez/c
void displayElements(fifolifo **e) {

	fifolifo *aux;
	char c;
	
	if (isEmpty(*e))
		printf("empty FIFO\n");
		
	else {

		initialize(&aux);
		
		while (!isEmpty(*e)) {
		
			printf("ELEMENT: %c\n", displayElement(*e));
			insertFIFO(&aux, removeElement(e));
			
		}
		
		while (!isEmpty(aux))
			insertFIFO(e, removeElement(&aux));

	}

}
コード例 #2
0
ファイル: LIB02.c プロジェクト: daniloax/lic
int main() {

	FILE *f;
	char c, fileName[10];
	fifolifo *fifo, *lifo;
	
	initialize(&fifo);
	initialize(&lifo);
	
	do {
	
		printf("FILENAME: ");
		scanf("%[^\n]s", fileName);
		getchar();
		
		f = fopen(fileName, "r");
		
		if (!f)
			printf("'%s' not exist\n", fileName);
	
	} while (!f);
	
	while (((c = getc(f)) != EOF) && (c != '\n'))
		insertFIFO(&fifo, c);
		
	fclose(f);
	displayElements(&fifo);
	system("pause");
	return 0;

}
コード例 #3
0
unsigned getUsers ( char * searchKey , userDataType ** firstFound )
{
  unsigned retCode, retCode2;
  unsigned counter , secondCounter;
  char usersFileName [MAX_LENGTH_LONG_FILENAME+1];
  userDataType buffer;
  FILE * readFile;
  boolean matches;
  userDataType * lastFound = NULL;
    
  if (! searchKey )
    return ( GET_USERS__INVALID_SEARCH_KEY );
     
  if (( retCode = getLongFilename ( DATA_DIR , USERS_FILE_NAME , usersFileName )) != OK )
    return (retCode);
    
  if (!(readFile = fopen ( usersFileName , "r" )))
  {
    if (errno != ENOENT)
      return ( GET_USERS__ERROR_OPENING_USERS_FILE_FOR_READING );
    return ( GET_USERS__USERS_FILE_DOES_NOT_EXIST );
  }
  
  ( * firstFound ) = NULL;
  matches = true;
  
  for( retCode = 0 ; retCode != GET_USER_ID__END_OF_FILE ; )  
  {
    if (( retCode = getUserData ( readFile , USERS_FILE_NAME , &buffer )) != OK )
    {
      if (retCode != GET_USER_ID__END_OF_FILE)
      {
        fclose ( readFile );
	freeFIFOResources ( firstFound , &lastFound );
        return ( retCode );
      }
    }
    
    if ( retCode != GET_USER_ID__END_OF_FILE )
      {
        for ( matches = false , counter = 0 ; ( (buffer.name[counter] != EOS) && ( !matches ) ) ; counter++ )
	  if ( buffer.name[counter] == searchKey[0] )
	  {
	    matches = true;  
	    for ( secondCounter = 1 ; ( ( searchKey[secondCounter] != EOS ) && ( matches ) ) ; secondCounter++ )
	      if ( searchKey [secondCounter] != buffer.name [counter + secondCounter] )
	        matches = false;
	  }  
        if ( matches )
	{
	  if( ( retCode2 = insertFIFO ( firstFound, &lastFound, &buffer ) ) != OK )
	  {
	    fclose ( readFile );
	    freeFIFOResources ( firstFound , &lastFound );
	    return ( retCode2);
	  }  
	}
      }
  }
 // fclose ( readFile );
  if ( ! ( * firstFound ) )
    return ( GET_USERS__NO_USER_FOUND );
  return ( OK ); 
}