int main() { slist_t *head = NULL, *tail = NULL; size_t list_size = 0; int i, ret; time_t t; time (&t); srand (t); for (i = 13; i > 0; i--) { ret = insert_at_head (&head, &tail, &list_size, (rand() % 10)); if (ret < 0) { destroy_list (&head, &tail); return -1; } } print_list (&head); delete_duplicates (&head, &list_size); print_list (&head); destroy_list (&head, &tail); print_list (&head); return 0; }
int main() { struct node * A = NULL; struct node * B = NULL; int x,y; while(1) { scanf("%d",&x); if(x) { scanf("%d %d",&x,&y); insert(&A,x,y); } else break; } while(1) { scanf("%d",&x); if(x) { scanf("%d %d",&x,&y); insert(&B,x,y); } else break; } mergesort(&A); mergesort(&B); struct node * C; C = merge(A,B); delete_duplicates(C); print(C); }
int main(int argc,char ** argv) { char string_to_search[100] = ""; char Argument[100] = ""; char File_Name[50][50]; int Arg_Number[10] = { -1 }; // Table for storing the number-A-B-C etc. ... Arg_Number [0] = Number-A ... int Number_of_line = 0; int i = 0, j = 0, size_name_file = 0, nb_line = 0, nb_file = 0; FILE* file = NULL; FILE * file_recursive; file_recursive = fopen("File_list.txt","w+"); if(arg_help(argc,argv) != 0) return -1; // Management -- help if(arg_long(argc,argv) != 0) return -1; // Management of -- and convertion for(j=1; j<argc; j++) // Loop to retrieve the data parameters sent (argument + string to search + file(s)) { if(argv[j][0]== '-') { strcat(Argument,argv[j]); if(argv[j][1] == 'A') { j++; Arg_Number[0] = atoi(argv[j]); j++; } else if(argv[j][1] == 'B') { j++; Arg_Number[1] = atoi(argv[j]); j++; } else if(argv[j][1] == 'C') { j++; Arg_Number[2] = atoi(argv[j]); j++; } else if(argv[j][1] == 'e') { j++; strcpy(string_to_search,argv[j]); } else if(argv[j][1] == 'm') { j++; Arg_Number[3] = atoi(argv[j]); j++; } } else // Recover the rest ( String to search + File list ) { strcpy(File_Name[size_name_file],argv[j]); if(size_name_file != 0) fprintf(file_recursive,"%s\n",argv[j]); size_name_file++; } } if(strcmp(string_to_search,"") == 0) { strcpy(string_to_search,File_Name[0]); //String to search i = 1; // Change the value for i to browse for the name of the files } else { i = 0; } delete_duplicates(Argument); // To delete duplicates for(j=0; j<=strlen(Argument); j++) // To delete the "-" at the beginning { Argument[j] = Argument[j+1]; } nb_file = size_name_file; // Knowing the number of file if(i == 1) // If accomodation File_Name[0] = string_to_search { nb_file = size_name_file - 1; } if(nb_file == 0) { char ** array1 = NULL; FunctionGrepWithArguments(array1,string_to_search,0,Argument,"",nb_file,Number_of_line,Arg_Number); } if(isWrong(Argument, argc) == 1) // Management of error return 0; if(strstr(Argument,"R")) // Recording in a text file { for(i; i<size_name_file; i++) { fclose(file_recursive); file_recursive = fopen("File_list.txt","w+"); list_recursively(File_Name[i],file_recursive); } nb_file = 2; } rewind(file_recursive); char chaine[TAILLE_MAX]; while(fgets(chaine, TAILLE_MAX, file_recursive) != NULL) { char chaine1[TAILLE_MAX]; int h; for(h = 0 ; h < strlen(chaine)-1; h++) { chaine1[h] = chaine[h]; } chaine1[h] = '\0'; file = fopen(chaine1, "r"); // Open file if (file != NULL) { nb_line = NbLine(file); char tableau[nb_line][TAILLE_MAX]; // Initializing a 2 dimension table containing the file RemplirTableau(file,tableau); // Fills the table FunctionGrepWithArguments(tableau,string_to_search,nb_line,Argument,chaine1,nb_file,Number_of_line,Arg_Number); } else { if(!strstr(Argument,"s")) printf("grep: %s: No such file or directory\n",chaine1); } } return 0; }
int main(int argc, char* argv[]) { if (argc < 2) { std::cerr << "Error: no file given\n"; print_usage(argv[0]); return EXIT_FAILURE; } // include paths std::vector<std::string> paths; std::string file_name, target_name, output_file; bool ignore_non_existing = true; // -MG bool add_empty_phony_targets = false; // -MP for (int i = 1; i < argc; i++) { const std::string arg(argv[i]); if (starts_with(arg, "-I") && arg.length() > 2) { paths.push_back(arg.substr(2)); continue; } if (arg == "-MG") { ignore_non_existing = false; continue; } if (arg == "-MM") { // ignore headers from system directories (default) continue; } if (arg == "-M") { std::cerr << "Warning: ignoring unsupported option " << arg << '\n'; continue; } if (arg == "-MD" || arg == "-MQ") { std::cerr << "Warning: ignoring unsupported option " << arg << '\n'; i++; continue; } if (arg == "-MP") { add_empty_phony_targets = true; continue; } if (arg == "-MT" && i + 1 < argc) { target_name = argv[++i]; continue; } if ((arg == "-MF" || arg == "-MMD" || arg == "-o") && i + 1 < argc) { output_file = argv[++i]; continue; } if (arg == "--help" || arg == "-h") { print_usage(argv[0]); return EXIT_SUCCESS; } // interpret last argument as file name if (i + 1 == argc) { file_name = arg; if (!file_exists(file_name)) { std::cerr << "Error: file does not exist: " << file_name << '\n'; return EXIT_FAILURE; } continue; } std::cerr << "Error: unknown option: " << arg << '\n'; print_usage(argv[0]); return EXIT_FAILURE; } // select output stream std::ofstream fstr(output_file); std::ostream* ostr = &std::cout; if (!output_file.empty()) { if (!fstr.good()) { std::cerr << "Error: cannot write to file " << output_file << '\n'; return EXIT_FAILURE; } ostr = &fstr; } // include paths paths.insert(paths.begin(), directory(file_name)); paths.push_back("."); paths = delete_duplicates(paths); // search for header inclusions in file const std::vector<std::string> dependencies = delete_duplicates( search_includes(file_name, paths, ignore_non_existing), Is_not_duplicate_ignore_path()); // prepend file itself to dependency list std::vector<std::string> dependencies_and_main(dependencies); dependencies_and_main.insert(dependencies_and_main.begin(), file_name); if (target_name.empty()) target_name = replace_extension(filename(file_name), "o"); // output print_dependencies(target_name, dependencies_and_main, *ostr); if (add_empty_phony_targets) print_empty_phony_targets(dependencies, *ostr); return EXIT_SUCCESS; }