int main (int argc, char **argv) { execname = basename (argv[0]); queue_ref queue = new_queue(); if (argc < 2) { putinqueue (queue, stdin, "-"); }else { for (int argi = 1; argi < argc; ++argi) { if (strcmp (argv[argi], "-") == 0) { putinqueue (queue, stdin, "-"); }else { putfileinqueue (queue, argv[argi]); } } } while (! isempty_queue (queue)) { char *oldstring = remove_queue(queue); printf ("%s\n", oldstring); free (oldstring); } free_queue(queue); return exit_status; }
int main (int argc, char **argv) { execname = basename(argv[0]); queue *the_queue = queue_new(); if (argc < 2) { putinqueue(the_queue, stdin, "-"); } else { for (int argi = 1; argi < argc; ++argi) { if (strcmp(argv[argi], "-") == 0) { putinqueue(the_queue, stdin, "-"); } else { putfileinqueue(the_queue, argv[argi]); } } } while (!queue_isempty(the_queue)) { char* tmp = queue_remove(the_queue); //assign a temp char pointer to point at the item printf("%s\n", tmp); //print the item free(tmp); //free the pointer } queue_free(the_queue); //free the queue return exit_status; }
int main (int argc, char **argv) { execname = basename(argv[0]); queue *the_queue = queue_new(); if (argc < 2) { putinqueue(the_queue, stdin, "-"); } else { for (int argi = 1; argi < argc; ++argi) { if (strcmp(argv[argi], "-") == 0) { putinqueue(the_queue, stdin, "-"); } else { putfileinqueue(the_queue, argv[argi]); } } } while (!queue_isempty(the_queue)) { queue_item_t temp = queue_remove(the_queue); printf("%s\n", temp); free(temp); } queue_free(the_queue); return exit_status; }
void putfileinqueue (queue_ref queue, char *filename) { FILE *input = fopen (filename, "r"); if (input == NULL) { fflush (NULL); fprintf (stderr, "%s: %s: %s\n", execname, filename, strerror (errno)); fflush (NULL); exit_status = EXIT_FAILURE; }else { putinqueue (queue, input, filename); fclose (input); } }
int main (int argc, char **argv) { execname = basename(argv[0]); Queue *the_queue = queue_new(); if (argc < 2) { putinqueue(the_queue, stdin, "-"); } else { for (int argi = 1; argi < argc; ++argi) { if (strcmp(argv[argi], "-") == 0) { putinqueue(the_queue, stdin, "-"); } else { putfileinqueue(the_queue, argv[argi]); } } } while (!queue_isempty(the_queue)) { printf("%s\n", queue_remove(the_queue)); } return 0; }
int main (int argc, char **argv) { execname = basename (argv[0]); queue *the_queue = new_queue(); if (argc < 2) { putinqueue (the_queue, stdin, "-"); }else { for (int argi = 1; argi < argc; ++argi) { if (strcmp (argv[argi], "-") == 0) { putinqueue (the_queue, stdin, "-"); }else { putfileinqueue (the_queue, argv[argi]); } } } while (! isempty_queue (the_queue)) { printf ("%s\n", remove_queue (the_queue)); } return exit_status; }