Thread: argc and argv not initialized properly (Visual Studio)

  1. #16
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > because if I use fgets(filename, sizeof(filename),stdin) the pointer bmpInput becomes NULL and the program terminated prematurely. I don't know why.
    That would be because fgets() also stores newline as well, and when it tries to find "filename\n", it will fail.

    If you had implemented some decent error handling (say calling perror() ), then you might have discovered "file not found" and perhaps figured this out.

    Additionally, see the FAQ on how to handle newlines with fgets().

    As for the "corruption", you need to post REAL code, not some made-up "something like this" code. If you're not smart enough to figure out the problem, you're not smart enough to make a facsimile program either - the critical information will disappear because you don't know what it is.
    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.

  2. #17
    Registered User
    Join Date
    Feb 2010
    Posts
    44
    @nonoob: I agree with that.
    @rags_to_riches: apart from the line: int getImageInfo(FILE*, long, int); in functions.h it is the entirety of the code. For the filename I enter "C:\bitmapje.bmp" which is a bitmap with 570x33 resolution.

  3. #18
    Registered User
    Join Date
    Feb 2010
    Posts
    44
    @Salem: I don't understand why you have to get nasty about this, I'm simply asking a question. As I wrote several times before it is the real code, there is nothing more to it. As for perror() I have never heard of it, I'll look it up. Thanks for the suggestion. I'm not claiming to be a professional, that's why I asked the question.

  4. #19
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Works fine for me on Linux, although you should not need alloca.h

    Where it's Windows, and \ is an escape character, try entering c:\\bitmapje.bmp for the filename (two \ s)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. argv and argc
    By antros48 in forum C Programming
    Replies: 19
    Last Post: 09-30-2011, 08:26 AM
  2. how to use argc and argv
    By Salahuddin in forum C Programming
    Replies: 19
    Last Post: 09-09-2011, 03:53 AM
  3. argc, argv
    By Martas in forum C Programming
    Replies: 6
    Last Post: 11-19-2009, 09:39 AM
  4. Replies: 14
    Last Post: 12-26-2004, 11:18 AM
  5. argc--; argv++;
    By C of Green in forum C++ Programming
    Replies: 5
    Last Post: 08-13-2003, 06:16 PM