Thread: the variable is being used without being initialized c

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    9

    Red face the variable is being used without being initialized c

    The progrm runs then when I enter a number this comes up in a error message then my program close
    The variable is being used without being initialized c

    this is the code
    Last edited by bob_999; 01-08-2011 at 06:28 PM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    If you're using gets, you've already lost. In this case, not only are you using gets, but you are using it incorrectly (the parameter passed to it is supposed to be a char*, not an int, and surely needs to point at actual memory (hint: 00 is not actual memory)).

    EDIT: I suppose I should be very clear about this: take any use of gets right out of your program. You can use fgets, or scanf, as you wish.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Code:
       int SearchName = 00;
       gets(SearchName);
    basically reads in data from the user and writes it - using the unsafest function you could have found for reading a string, gets() - to a NULL pointer. That is a crash waiting to happen.

    If you are getting complaints from your compiler, address them first. But, basically, in current form, your code is rubbish.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  4. #4
    Registered User
    Join Date
    Jan 2011
    Posts
    9
    its now said Error 15 error C2198: 'fgets' : too few arguments for call c:\documents and settings\stevie\desktop\project65\project65\gympro ject2\gymproject2\gymproject2\gymproject2.c 239

  5. #5
    Registered User
    Join Date
    Jun 2009
    Posts
    486
    fgets takes more arguments than gets. Try google.
    C is fun

  6. #6
    Registered User \007's Avatar
    Join Date
    Dec 2010
    Posts
    179
    This guy is still at it?

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by bob_999 View Post
    The progrm runs then when I enter a number this comes up in a error message then my program close
    The variable is being used without being initialized c

    this is the code
    Hi Bob... Mind if I chip in just a little bit of advice here?

    In your place I would post the problem code, clearly highlighting the parts that are producing errors, and explaining what you've already done to try and fix it...

    The hassle you're getting seems more related to how you are asking the question than anything else... (loony BASIC examples, aside).

  8. #8
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by CommonTater View Post
    The hassle you're getting seems more related to how you are asking the question than anything else... (loony BASIC examples, aside).
    Before he edited the original post to remove the code, that code contained no variable named c, initialised or not. It therefore had absolutely no relevance to the problem described.

    When someone can't be bothered applying the effort to ask a meaningful question, they tend to get static.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to put a check on an extern variable set as flag
    By rebelsoul in forum C Programming
    Replies: 18
    Last Post: 05-25-2009, 03:13 AM
  2. how do I know a variable is not initialized?
    By patiobarbecue in forum C++ Programming
    Replies: 7
    Last Post: 01-17-2009, 06:49 AM
  3. Question about printing a variable???
    By Hoser83 in forum C++ Programming
    Replies: 2
    Last Post: 03-31-2006, 01:57 PM
  4. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 12:07 PM
  5. static class variable vs. global variable
    By nadamson6 in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2005, 03:31 PM