2D arrays programming, please help

This is a discussion on 2D arrays programming, please help within the C Programming forums, part of the General Programming Boards category; What am I doing wrong in coding this 2D arrays program? I get 2 errors and do not know how ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,497
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    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, 08:05 PM
  5. how can i pass 2d arrays
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 11-02-2001, 06:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21