Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8597215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:51:49+00:00 2026-06-12T00:51:49+00:00

#include <stdlib.h> #include <stdio.h> #include <getopt.h> #include mylib.h #include tree.h /* A boolean type

  • 0
#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>
#include "mylib.h"
#include "tree.h"

/* A boolean type which can be TRUE or FALSE */
typedef enum bool_e {FALSE, TRUE} bool_t;

static void usage(char *progname);
static void setup(int argc, char **argv, char **filename, bool_t *rbt,
                  bool_t *do_depth, bool_t *p_order, bool_t *output_graph);
static void make_graph(char *filename, tree t);

static void usage(char *prog_name) {
   fprintf(stderr, "Usage: %s [OPTION]... <STDIN>\n\n%s%s", prog_name,
           "Perform various operations using a hash-table.  By default read\n"
           "words from stdin and print them with their frequencies to stdout.\n\n"
           " -d       prints the tree depth\n"
           " -p       prints the tree in pre_order\n"
           " -o FILENAME prints output to a specified file\n\n"
           " -r       creates a rbt tree\n"
           " -h       Display this message\n\n");
}

static void print_key(char *key) {
   printf("%s\n", key);
}

static void make_graph(char *filename, tree t) {
   FILE *file = fopen(filename, "w");
   fprintf(stderr, "Creating dot file '%s'\n", filename);
   tree_output_dot(t, file);
   fclose(file);
}



/**
 * Handle options given on the command-line by setting a number of
 * variables appropriately.  May call usage() if incorrect arguments
 * or -h given.
 *
 * @param argc the number of command-line arguments.
 * @param argv an array of strings contain the command-line arguments.
 * @param rbt is created if -r is given
 * @param the tree depth is printed if d is given
 * @param tree_outputfile_dot is called if -o output-filename is given
 */

int main(int argc, char **argv) {
   bool_t rbt = FALSE, do_depth = FALSE, p_order = FALSE, output_graph = FALSE;
   tree_t tree_type = BST;
   tree t;
   char word[256];
   char *dot_filename;

   setup(argc, argv, &dot_filename, &rbt, &do_depth, &p_order, &output_graph);
   if (rbt) {
     t = tree_new(RBT);
   } else {
      t = tree_new(tree_type);
   }
   while ((getword(word, sizeof word, stdin)) != EOF) {
      t = tree_insert(t, word);
   }

   if (do_depth) {
      printf("%d\n", tree_depth(t));
   } else if (p_order) {
      tree_preorder(t, print_key);
   } else if (output_graph) {
       make_graph(dot_filename, t);
    } else {
      tree_inorder(t, print_key);
   }


   t = tree_free(t);
   return EXIT_SUCCESS;
}


static void setup(int argc, char **argv, char **filename, bool_t *rbt,
                  bool_t *do_depth, bool_t *p_order, bool_t *output_graph) {
   const char *optstring = "do:prh";

   char option;

   while ((option = getopt(argc, argv, optstring)) != EOF) {
      switch (option) {
      case 'd':
        *do_depth = TRUE;
         break;
      case 'o':
         *filename = optarg;
         *output_graph = TRUE;
         break;
      case 'p':
         *p_order = TRUE;
         break;
      case 'r':
         *rbt = TRUE;
         break;
      case 'h':
      default:
         usage(argv[0]);
         exit(EXIT_SUCCESS);
      }
   }
}

Hi everyone, I’m trying to compile this code, and I’m running into a problem I don’t know how to fix. My file compiles with one warning, and I would like to remedy it.

main.c: In function ‘main’:
main.c:56: warning: ‘dot_filename’ may be used uninitialized in this function

I’m not really sure how I would get around fixing this problem, I don’t usually work with file opening stuff often, and I’m not really sure what to do. What would I do to make this warning go away?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:51:50+00:00Added an answer on June 12, 2026 at 12:51 am

    You can simply initialize dot_filename with a null pointer.

    char *dot_filename = NULL;
    

    That should fix the warning.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct dict_pair { void *key; void *value;
#include <stdio.h> #include <stdlib.h> typedef struct { char *Name; int grade; int cost; }Hotel;
#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> typedef struct
#include <stdio.h> #include <stdlib.h> typedef int element; struct cell { element e; struct cell
#include <stdio.h> #include <stdlib.h> typedef struct nod{ int data; struct nod *left,*right; }NOD; NOD
#include<stdio.h> #include<stdlib.h> char* re() { char *p = hello; return p; } int main()
#include <stdio.h> #include <stdlib.h> int main(void) { int x; int *in, *begin; in =
#include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { if(argc != 2) return
#include<stdio.h> #include<stdlib.h> struct node { int data; struct node *next; }; void insert( struct
#include <stdio.h> #include <stdlib.h> #include <time.h> void initDeck (int deck[]); void showDeck (int deck[]);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.