Thread: Syntax Trouble

  1. #1
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903

    Syntax Trouble

    I am having second thoughts about the book I am studying.. on more than one occasion, I have ended up debugging the author's examples... (Windows Programming with C++ -Henning Hansen) Here is my latest example:

    Code:
    LRESULT CALLBACK WndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam)
    {
            
    
        static BYTE Pixel[6][5] = {0, 255, 0, 255, 0,  0, 
                                   255, 0, 255, 0 255, 0, 
                                   0, 255, 0, 255, 0,  0,
                                   255, 0, 255, 0, 255,0,
                                   0, 255, 0, 255, 0,  0};
    
    
        static HBITMAP hBitmap;
        static HDC hdcmem;
    
        switch(msg)
        {
    
            case WM_LBUTTONDOWN:
    The program compiles except for one error.. stating that Pixel data structure was terminated incorrectly..

    This method for initializing a 2D array looks kinda shady to me..

    Q: is there a better/preferred method for initializing a 2D array like the one above..??

    thanks in advance
    Last edited by The Brain; 02-20-2005 at 08:58 AM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  2. #2
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Code:
    static BYTE Pixel[6][5] = {0, 255, 0, 255, 0,  0, 
                                   255, 0, 255, 0, 255, 0, 
                                   0, 255, 0, 255, 0,  0,
                                   255, 0, 255, 0, 255,0,
                                   0, 255, 0, 255, 0,  0};
    Looks like you missed a comma.
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Each dimension needs it's own set of braces
    Code:
        static BYTE Pixel[6][5] = { {0, 255, 0, 255, 0,  0}, 
                                   { 255, 0, 255, 0 255, 0 }, 
                                   { 0, 255, 0, 255, 0,  0 },
                                   { 255, 0, 255, 0, 255,0 },
                                   { 0, 255, 0, 255, 0,  0 }};
    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.

  4. #4
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    good suggestions.. program works great
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM