int main(void) { List movies; Item temp; /* initialize */ InitializeList(&movies); if (ListIsFull(&movies)) { fprintf(stderr,"No memory available! Bye!\n"); exit(1); } /* gather and store */ puts("Enter first movie title:"); while (get(temp.title, TSIZE) != NULL && temp.title[0] != '\0') { puts("Enter your rating <0-10>:"); scanf("%d", &temp.rating); while(getchar() != '\n') continue; if (AddItem(temp, &movies)==false) { fprintf(stderr,"Problem allocating memory\n"); break; } if (ListIsFull(&movies)) { puts("The list is now full."); break; } puts("Enter next movie title (empty line to stop):"); } /* display */ if (ListIsEmpty(&movies)) printf("No data entered. "); else { printf ("Here is the movie list:\n"); Traverse(&movies, showmovies); } printf("You entered %d movies.\n", ListItemCount(&movies)); /* clean up */ EmptyTheList(&movies); printf("Bye!\n"); return 0; }
int main(void) { List movies; Item temp; /* Initialize */ InitializeList(&movies); if(ListIsFull(&movies)) { fprintf(stderr,"No memory avaliable! Bye!\n"); exit(1); } /* collecte and storage data */ puts("Enter first movie title :"); while(gets(temp.title) != NULL && temp.title[0] != '\0') { puts("Enter your rating <0-10> : "); scanf("%d",&temp.rating); while(getchar() != '\n'); if(AddItem(temp,&movies) == false) { fprintf(stderr,"Problem allocating memory\n"); break; } if(ListIsFull(&movies)) { puts("The list id full."); break; } puts("Enter next movie title (empty line to quit):"); } /* Display List */ if(ListIsEmpty(&movies)) printf("No data entred."); else { printf("Here is the movie list :\n"); Traverse(&movies,showmovies); } printf("Your entered %d movies.\n",ListItemCount(&movies)); /* clean list */ EmptyTheList(&movies); printf("Bye!\n"); return 0; }
int main(int argc, char ** argv) { List movies; Item temp; /* 初始化 */ InitializeList(&movies); if (ListIsFull(&movies)){ fprintf(stderr, "No memory available! Bye!\n"); exit(EXIT_FAILURE); } /* 收集并存储 */ fputs("Enter first movie title: \n", stdout); while (fgets(temp.title, TSIZE, stdin) != NULL && temp.title[0] != '\n'){ reject_ch(temp.title, '\n'); fputs("Enter your rating<0-10>: \n", stdout); scanf_s("%d", &temp.rating); while (getchar() != '\n'){ continue; } if (false == AddItem(&temp, &movies)){ fprintf(stderr, "Problem allocating memory\n"); exit(EXIT_FAILURE); } if (ListIsFull(&movies)){ fputs("The list is now full.\n", stdout); break; } fputs("Enter next movie title(empty line to stop): \n", stdout); } /* 显示 */ if (ListIsEmpty(&movies)) printf("No data entered."); else{ printf("Here is the movie list: \n"); Traverse(&movies, showMovies); } printf("You entered %d movies.\n", ListItemCount(&movies)); /* 清除 */ EmptyTheList(&movies); printf("Bye!\n"); _CrtDumpMemoryLeaks(); return EXIT_SUCCESS; }
int main() { List plist; char ch; InitalizeList(&plist); if (ListIsFull(&plist)) { fprintf(stderr,"List is full!\n"); exit(EXIT_FAILURE); } while((ch = menu()) != 'q') { switch(ch) { case 'a': AddItem(&plist); break; case 'd': deleteItem(&plist); break; case 's': show(&plist); break; default: puts("Error inputing!"); break; } } EmptyList(&plist); puts("Thanks for using!"); return 0; }
int main() { List movies; Item temp; InitializeList(&movies); if(ListIsFull(&movies)) { fprintf(stderr,"no memory available!\nBye!\n"); exit(1); } puts("enter first movie title:"); while(gets(temp.title) != NULL && temp.title[0] != '\0') { puts("enter your rating:"); scanf("%d",&temp.rating); while(getchar() != '\n') continue; if(AddItem(temp,&movies) == false) { fprintf(stderr,"Problem allocating memory\n"); break; } if(ListIsFull(&movies)) { puts("the list is full"); break; } puts("enter next movie title:"); } if(ListIsEmpty(&movies)) { printf("no data entered."); } else { printf("here is the movie list:\n"); Traverse(&movies,ShowMovies); } printf("you entered %d movies.\n",ListItemCount(&movies)); EmptyTheList(&movies); printf("Bye!\n"); return 0; }
int main(void) { List movies; Item temp; /*初始化*/ InitializeList(&movies); if(ListIsFull(&movies)) { fprintf(stderr,"no memory available!\n"); exit(1); } /*收集并存储*/ puts("enter first movie title"); while(fgets(temp.title,TSIZE,stdin) != NULL && temp.title[0] != '\n') { puts("enter your rating <0-10>:"); scanf("%d",&temp.rating); while(getchar() != '\n') continue; if(AddItem(temp,&movies) == false) { fprintf(stderr,"problem allocating memory\n"); break; } if(ListIsFull(&movies)) { puts("the list is now full."); break; } puts("enter next movie title(empty line to stop)"); } if( ListIsEmpty(&movies) ) printf("no data entered."); else { printf("here is the movie list:\n"); Traverse(&movies,showmovies); } printf("your entered %d movies.\n",ListItemCount(&movies) ); /*清除*/ EmptyTheList(&movies); printf("bye!\n"); return 0; }
int main(void){ List movies; Item temp; //初始化 InitializeList(&movies); if(ListIsFull(&movies)){ fprintf(stderr,"No memory available!"); exit(1); } //收集并储存 puts("Enter first movie title:"); while(gets(temp.title ) != NULL && temp.title [0] != '\0' ){ puts("Enter your rating <0-10>:"); scanf("%d",&temp.rating ); while(getchar()!='\n'){ continue; } if(AddItem(temp,&movies)==false){ fprintf(stderr,"Problem allocating memory\n"); break; } if(ListIsFull(&movies)){ puts("The list is full."); break; } puts("Enter next movie title(empty line to stop))"); } //显示 if(ListIsEmpty(&movies)){ printf("No data entered."); } else{ printf("Here is the movie list:\n"); Traverse(&movies,showmovies); } //清除 EmptyTheList(&movies); printf("Bye!"); return 0; }
/* adding item to list */ bool AddItem(Item item, List * plist) { if(ListIsFull(plist)) { puts("The list ia full, add faild"); return false; } plist->entries[plist->items] = item; plist->items++; return true; }
//向列表中添加元素 void AddItem(List * plist) { Item temp; puts("Please input the carid:"); scanf("%d",&temp.carid); delMore(); puts("Please enter the car's trademark:"); gets(temp.trademark); temp.flag = false; if(ListIsFull(plist)) { fprintf(stderr,"List is full!\n"); } else { if(AddItemToList(&temp,plist) == false) { fprintf(stderr,"Add item failed!\n"); exit(EXIT_FAILURE); } } }
int wmain( int argc, LPTSTR argv[] ) { // Vars declarations int targetDirInd = 0; BOOL flags[ MAX_OPTIONS ] = { 0 }; TCHAR workDir[ MAX_PATH ] = { 0 }; TCHAR targetDir[ MAX_PATH ] = { 0 }; DWORD workLength = 0; List resultsList = { 0 }; Item resultsItem = { 0 }; PVOID oldValueWow64 = NULL; BOOL wow64Disabled = FALSE; TCHAR* ptTchar = NULL; // Get index of first argument after options // Also determine which options are active targetDirInd = Options( argc, argv, TEXT( "h" ), &flags[ FL_HELP ], NULL ); // Get current working dir workLength = GetCurrentDirectory( _countof( workDir ), workDir ); // Validate target dir if ( ( argc > targetDirInd + 1 ) || flags[ FL_HELP ] ) { // More than one target or // target with gaps (no quotes) specified or // asked for help // Print usage wprintf_s( TEXT( "\n Usage: jdots [options] [target dir]\n\n" ) ); wprintf_s( TEXT( " Options:\n\n" ) ); wprintf_s( TEXT( " -h : Print usage\n\n" ) ); wprintf_s( TEXT( " If no target dir is specified, then the current working dir will be used\n" ) ); return 1; } else if ( ( argc < targetDirInd + 1 ) && ( workLength <= MAX_PATH - 3 ) ) { // No target specified --> assume current dir wcscpy_s( targetDir, MAX_PATH, workDir ); } else if ( argc == targetDirInd + 1 ) { // One target specified // Validate target dir starting with '\' if ( argv[ targetDirInd ][ 0 ] == '\\' ) { // Fetch drive letter from working dir wcsncpy_s( targetDir, MAX_PATH, workDir, 2 ); } // Append passed dir to target dir wcscat_s( targetDir, MAX_PATH, argv[ targetDirInd ] ); } // Set up absolute target dir --> resolve '.' and '..' in target dir if ( !SetCurrentDirectory( targetDir ) ) { ReportError( TEXT( "\nTarget directory not found.\n" ), 0, TRUE ); return 1; } // Display absolute target dir GetCurrentDirectory( _countof( targetDir ), targetDir ); wprintf_s( TEXT( "\n Target dir: \"%s\"\n\n" ), targetDir ); // Initialize results list InitializeList( &resultsList ); // Initialize list's name (measurement name) ptTchar = wcsrchr( targetDir, L'\\' ); if ( ptTchar != NULL ) IniListName( &resultsList, ptTchar + 1 ); else IniListName( &resultsList, TEXT( "" ) ); // Check mem availability if ( ListIsFull( &resultsList ) ) { wprintf_s( TEXT( "\nNo memory available!\n" ) ); return 1; } // Disable file system redirection wow64Disabled = Wow64DisableWow64FsRedirection( &oldValueWow64 ); // Scan target dir scanDir( targetDir, &resultsList, &resultsItem ); // Re-enable redirection if ( wow64Disabled ) { if ( !( Wow64RevertWow64FsRedirection( oldValueWow64 ) ) ) ReportError( TEXT( "Re-enable redirection failed." ), 1, TRUE ); } // Display results if ( ListIsEmpty( &resultsList ) ) wprintf_s( TEXT( "\nNo data.\n\n" ) ); else { // Sort by name (a to Z) SortList( &resultsList, cmpItemsName ); // Display sorted results showResults( &resultsList, &resultsItem ); // Generate KML file outputKml( &resultsList ); } // Housekeeping EmptyTheList( &resultsList ); return 0; }
int wmain( int argc, LPTSTR argv[] ) { // Declare vars TCHAR targetDir[ MAX_PATH ] = { 0 }; TCHAR workDir[ MAX_PATH ] = { 0 }; DWORD targetLength = 0; DWORD workLength = 0; Item resultsItem = { 0 }; List resultsList = { 0 }; LARGE_INTEGER freq; LARGE_INTEGER startingT, endingT, elapsedTicks; BOOL flags[ MAX_OPTIONS ] = { 0 }; int targetDirInd = 0; PVOID oldValueWow64 = NULL; BOOL wow64Disabled = FALSE; // Fetch frec & initial ticks count QueryPerformanceFrequency( &freq ); QueryPerformanceCounter( &startingT ); // Get index of first argument after options // Also determine which options are active targetDirInd = Options( argc, argv, TEXT( "sfdmnthb" ), &flags[ FL_SIZE ], &flags[ FL_FILES ], &flags[ FL_DIRS ], &flags[ FL_MODIF ], &flags[ FL_NAME ], &flags[ FL_TYPE ], &flags[ FL_HELP ], &flags[ FL_DBG ], NULL ); // Get current working dir workLength = GetCurrentDirectory( _countof( workDir ), workDir ); // Validate target dir if ( ( argc > targetDirInd + 1 ) || flags[ FL_HELP ] ) { // More than one target or // target with gaps (no quotes) specified or // asked for help // Print usage wprintf_s( TEXT( "\n Usage: dgl [options] [target dir]\n\n" ) ); wprintf_s( TEXT( " Options:\n\n" ) ); wprintf_s( TEXT( " -s : Sort by size [bytes] (default)\n" ) ); wprintf_s( TEXT( " -f : Sort by files count (descending)\n" ) ); wprintf_s( TEXT( " -d : Sort by dirs count (descending)\n" ) ); wprintf_s( TEXT( " -m : Sort by date modified (latest to earliest)\n" ) ); wprintf_s( TEXT( " -n : Soft by name (a to Z)\n" ) ); wprintf_s( TEXT( " -t : Sort by type (<DIR>, <LIN>, file)\n" ) ); wprintf_s( TEXT( " -h : Print usage\n" ) ); wprintf_s( TEXT( " -b : Extended output (debug purposes)\n\n" ) ); wprintf_s( TEXT( " If no option is specidied, then '-s' will be used\n" ) ); wprintf_s( TEXT( " If no target dir is specified, then the current working dir will be used\n" ) ); return 1; } else if ( ( argc < targetDirInd + 1 ) && ( workLength <= MAX_PATH - 3 ) ) { // No target specified --> assume current dir wcscpy_s( targetDir, MAX_PATH, workDir ); } else if ( argc == targetDirInd + 1 ) { // One target specified // Validate target dir starting with '\' if ( argv[ targetDirInd ][ 0 ] == '\\' ) { // Fetch drive letter from working dir wcsncpy_s( targetDir, MAX_PATH, workDir, 2 ); } // Append passed dir to target dir wcscat_s( targetDir, MAX_PATH, argv[ targetDirInd ] ); } // Set up absolute target dir --> resolve '.' and '..' in target dir if ( !SetCurrentDirectory( targetDir ) ) { ReportError( TEXT( "\nTarget directory not found.\n" ), 0, TRUE ); return 1; } // Display absolute target dir GetCurrentDirectory( _countof( targetDir ), targetDir ); wprintf_s( TEXT( "\n Target dir: \"%s\"\n\n" ), targetDir ); // Initialize results list InitializeList( &resultsList ); if ( ListIsFull( &resultsList ) ) { wprintf_s( TEXT( "\nNo memory available!\n" ) ); return 1; } // Debug output if ( flags[ FL_DBG ] ) wprintf_s( TEXT( " %s\n" ), targetDir ); // Disable file system redirection wow64Disabled = Wow64DisableWow64FsRedirection( &oldValueWow64 ); // Scan target dir scanDir( targetDir, &resultsList, &resultsItem, TRUE, flags[ FL_DBG ] ); // Re-enable redirection if ( wow64Disabled ) { if ( !( Wow64RevertWow64FsRedirection( oldValueWow64 ) ) ) ReportError( TEXT( "Re-enable redirection failed." ), 1, TRUE ); } // Display results if ( ListIsEmpty( &resultsList ) ) wprintf_s( TEXT( "\nNo data.\n\n" ) ); else { // Sort results // if-else chain determines sorting priority // one sorting type high prio excludes low prio types if ( flags[ FL_SIZE ] ) // Sort by size (descending) SortList( &resultsList, cmpItemsSizeCount ); else if ( flags[ FL_FILES ] ) // Sort by files count (descending) SortList( &resultsList, cmpItemsFilesCount ); else if ( flags[ FL_DIRS ] ) // Sort by dirs count (descending) SortList( &resultsList, cmpItemsDirsCount ); else if ( flags[ FL_MODIF ] ) // Sort by modification date (latest to earliest) SortList( &resultsList, cmpItemsLastWriteTime ); else if ( flags[ FL_NAME ] ) // Sort by name (a to Z) SortList( &resultsList, cmpItemsName ); else // Default: sort by size (descending) SortList( &resultsList, cmpItemsSizeCount ); // Debug output if ( flags[ FL_DBG ] ) wprintf_s( TEXT( "\n" ) ); // Display sorted results showResults( &resultsList, &resultsItem ); } // Housekeeping EmptyTheList( &resultsList ); // Fetch final ticks count QueryPerformanceCounter( &endingT ); // Calc elapsed ticks elapsedTicks.QuadPart = endingT.QuadPart - startingT.QuadPart; // Calc and display elapsed time calcDispElapTime( &elapsedTicks.QuadPart, &freq.QuadPart ); return 0; }