Thread: variable used but uninitialized

  1. #1
    Registered User
    Join Date
    Apr 2022
    Posts
    1

    variable used but uninitialized

    Hy everyone, I need your help !
    I'm doing a little code for school but I have an issue : when I try to compile my code I have the following warning : "warning: 'nom' is used uninitialized [-Wuninitialized]".
    My issue is that nom is initialized two line above. Is someone could help me ?

    Code:
    char *demande_nom1()
    {
      char *nom;
      printf("Quel est le nom de l'image d'origine ?");
      scanf("%s", nom);
      return nom;
    }
    PS: yes i'm french
    Last edited by Salem; 04-15-2022 at 11:29 AM. Reason: Removed crayola

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Initialised means you used the = operator to give your variable a value.

    Hence uninitialised means you didn't do that, and you've no idea where nom is pointing.

    To make this code workable, you need something like
    char *nom = malloc(100);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Coverity report "Uninitialized scalar variable"
    By newer_c in forum C++ Programming
    Replies: 2
    Last Post: 06-16-2016, 11:13 PM
  2. Confused about an uninitialized bool variable.
    By assiduus in forum C Programming
    Replies: 4
    Last Post: 02-22-2011, 05:55 AM
  3. Uninitialized local variable
    By steeno321 in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2010, 07:46 PM
  4. uninitialized local variable 'XXXXXX' used
    By Brownie in forum C Programming
    Replies: 8
    Last Post: 02-26-2009, 06:41 AM
  5. uninitialized local variable question
    By raist in forum C++ Programming
    Replies: 5
    Last Post: 12-02-2006, 03:00 PM

Tags for this Thread