Thread: 2D arrays programming, please help

  1. #1
    Registered User
    Join Date
    Sep 2007
    Location
    Lowell, MA
    Posts
    9

    Unhappy 2D arrays programming, please help

    What am I doing wrong in coding this 2D arrays program? I get 2 errors and do not know how to solve the issue... I get "error C2061: syntax error : identifier 'letter'" and "error C2065: 'array' : undeclared identifier"
    Code:
     
    #include "stdafx.h"
    #include "stdio.h"
    #include "stdlib.h"
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    int col, row, x, y, width, height, stop=0, letter=3;
    
    do
    {
    printf("Enter x0, y0, width, height:");
    if(scanf_s("%i%i%i%i",&x,&y,&width,&height)==EOF)
    {
    	stop=1;
    }
    else
    {
    	printf("0000000000111111111122222222223333333333\n");
    	printf("0123456789012345678901234567890123456789");
    	for(row=0;row<x;row++)
    	{
    		if (row<10)
    		{
    			printf("0%d", row);
    			printf("\n");
    		}
    			else
    			{
    				printf("0%d", row);
    				printf("\n");
    			}
    	}
    	for(col=0;col<40;col++)
    	{
    	if((col==x)||(col==(x+width-1))||((row==y)||(row==(y+height-1))))
    	if((col>=x)&&(col<=(x+width-1))&&((row>=y)&&(row<=(y=height-1))))
    	{
    		array[row][col]=letter;
    	}
    	}
    }
    printf("%c",array[row][col]);
    printf("\n");
    }
    letter++;
    while(!stop);
    for(;;);
    return 0;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    So you don't think that given "undeclared identifier" that actually declaring the identifier in question is a good idea?
    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.

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    ohh this is funny, the error message itself says what the error is. you hanv't declared the those two identifiers. Declare and array with the name "array" and the "1letter".

    ssharish

  4. #4
    Registered User
    Join Date
    Sep 2007
    Location
    Lowell, MA
    Posts
    9
    Yeah, that was a stupid mistake regarding the arrays not being identified. Anyways, I am not sure what to do about the syntax error. I know I have to change something within "letter" but don't know what...

  5. #5
    Registered User
    Join Date
    Sep 2007
    Location
    Lowell, MA
    Posts
    9
    Nevermind, I did some rearranging. Thanks for the laughs, lol. I panicked...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2D Array's, assigning chars.
    By gman89 in forum C Programming
    Replies: 9
    Last Post: 04-26-2008, 11:03 PM
  2. returning 2D arrays
    By ... in forum C++ Programming
    Replies: 2
    Last Post: 09-02-2003, 12:28 PM
  3. Initialising 2D and 3D arrays
    By fry in forum C++ Programming
    Replies: 5
    Last Post: 08-01-2002, 04:34 AM
  4. Reading 2d arrays from file?
    By Ringhawk in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2002, 09:05 PM
  5. how can i pass 2d arrays
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 11-02-2001, 07:33 AM