8 Replies - 395 Views - Last Post: 03 February 2013 - 07:50 AM Rate Topic: -----

#1 hamidooooo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 02-February 13

error "length" is not a type!

Posted 02 February 2013 - 05:10 AM

i got an error in project "snake" its near 700 lines so i cant copy all of it. but the problem is the compiler gives me "length" is not a type.and its kinda weird.the language is "c"


"""""
struct snake_place
{
    int x ;
    int y ;
};

struct snake_data
{
    int length ;
    struct snake_place snake_array [50] ;
    struct snake_place head ;
    struct snake_place tail ;
    int direction ;
};
struct snake_data snake;



.........
........
void shift1(){
    int i;
    int snake,length,snake_array;
    int snake1;
        for (i = 0 ; i < snake1.length - 1 ; i++ ){
        snake1.snake_array[i] = snake1.snake_array[i+1] ;
        }
    }
 """""



in void shift1() there is an error i cant solve.and im in a hurry...

This post has been edited by jimblumberg: 02 February 2013 - 06:09 AM
Reason for edit:: Added missing code tags. Please learn to use them properly.


Is This A Good Question/Topic? 0
  • +

Replies To: error "length" is not a type!

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2117
  • View blog
  • Posts: 3,242
  • Joined: 21-June 11

Re: error "length" is not a type!

Posted 02 February 2013 - 05:15 AM

I'm not sure why you get the error message you do (presumably the piece of code that causes that error message isn't part of the code you've posted), but snake1.length doesn't make any sense since snake1 is an integer, not a struct or union that has a length field.

PS: Next time it would be great if you posted a small code sample that produces the error message you're asking about when compiled and if you posted the whole error message including line numbers.

This post has been edited by sepp2k: 02 February 2013 - 05:18 AM

Was This Post Helpful? 0
  • +
  • -

#3 hamidooooo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 02-February 13

Re: error "length" is not a type!

Posted 02 February 2013 - 06:00 AM

wow what a mistake!!!! i think u r right tnx for quick answering.i will correct it and see what happens..
Was This Post Helpful? 0
  • +
  • -

#4 hamidooooo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 02-February 13

Re: error "length" is not a type!

Posted 03 February 2013 - 06:23 AM

i have a really hard situation.i wrote about 700 lines in "c" language and have some errors in my program.i will copy my whole game here and im in a hurry too.if someone could correct it for me.u can copy it into your compiler and see the errors.my compiler is dev++.heres is my code.please answer me quick and compelete.tnx.


#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <time.h>

#define max3(a,b,c) ( (a)>=(B)/>/> ? ( (a)>(c) ? (a) : (c) ) : ( (B)/>(c) ? (B)/> : (c) ) )

#define UP 1
#define DOWN 2
#define LEFT 3
#define RIGHT 4
#define UP1 5
#define DOWN1 6
#define LEFT1 7
#define RIGHT1 8

#define EXIT 0
#define COUNTINUE 9

struct snake_place
{
    int x ;
    int y ;
};

struct snake_data
{
    int length ;
    struct snake_place snake_array [50] ;
    struct snake_place head ;
    struct snake_place tail ;
    int direction ;
};
struct snake_data snake;
void gotoxy(int x, int y)
{
  COORD coord;
  coord.X = x;
  coord.Y = y;
  SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void setcolor(unsigned short color)
{
    HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hcon,color);
}
void snakeCreation(){
	    int i,len,x,y;
	    struct snake_place temp ;

	    //snake
	    setcolor(13);
	    printf("snake length :");
	    scanf("%d",&len);
	    snake.length = len ;
	    printf("first location snake : (x,y)");
	    scanf("%d %d",&x,&y);
	    snake.head.x = x ;
	    snake.head.y = y ;
	    temp = snake.head ;
	    for (i = len - 1; i >= 1 ; i-- ){
	        snake.snake_array[i] = temp ;
	        temp.x--;
	        }
	    snake.tail.x = temp.x ;
	    snake.tail.y = temp.y ;

	    system("cls");
	}

	void snakeDraw(struct snake_data snake)
	{
	    int i ;
	    gotoxy(snake.head.x,snake.head.y);
	    printf("$");
	    gotoxy(snake.tail.x,snake.tail.y);
	    printf("@");
	    for (i=1;i<snake.length - 1;i++){
	        gotoxy(snake.snake_array[i].x,snake.snake_array[i].y);
	        printf("0");
	        }
	}

	void shift(){
	    int i;
	    for (i = 0 ; i < snake.length - 1 ; i++ ){
	        snake.snake_array[i] = snake.snake_array[i+1] ;
	        }
	}


	int getInput()
	{
	    char c ;
	    int arrow,arrow2;
	    arrow = getch ();

	    if(arrow==224)
	    {
	        arrow2 = getch ();
	        if(arrow2==72)
	            return UP ;
	        else if(arrow2==80)
	            return DOWN;
	        else if(arrow2==75)
	            return LEFT ;
	        else if(arrow2==77)
	            return RIGHT ;
	    }
	    if (arrow == 27 )
	    {
	        system("cls");
	        setcolor(666);
	        gotoxy(30,10);
	        printf("DO YOU WANT TO EXIT ?");
	        gotoxy(36,11);
	        printf(" Y / N ");
	        c = getch();
	        if (c == 'y' || c == 'Y'){
	            return EXIT ;
	            }
	        else if (c == 'N' || c == 'n'){
	        	system("cls");
	        	//wall();
	            return COUNTINUE ;
	        	}
	        return 0;
	    }
	    else
	    	return COUNTINUE ;
	}

	void moveSnake(int direction)
	{
		//snake
	    if (direction == DOWN && snake.direction != UP ){
	        snake.snake_array[snake.length - 1 ] = snake.head ;
	        if (snake.head.y<25){
	        snake.head.y++;
	        }
	        else{
	            snake.head.y = 0 ;
	            }

	        shift();
	        gotoxy(snake.tail.x,snake.tail.y);
	            printf(" ");  // instead of cls
	        snake.tail = snake.snake_array[0];
	        return ;
	    }

	    if (direction == UP && snake.direction != DOWN ){
	        snake.snake_array[snake.length - 1 ] = snake.head ;
	        if (snake.head.y>0){
	            snake.head.y--;
	        }
	        else {
	            snake.head.y = 25 ;
	            }
	        shift();
	        gotoxy(snake.tail.x,snake.tail.y);
	                   printf(" ");   // instead of cls
	        snake.tail = snake.snake_array[0];
	        return ;
	    }
	    if (direction == LEFT && snake.direction != RIGHT ){
	        snake.snake_array[snake.length - 1 ] = snake.head ;
	        if (snake.head.x>0 ){
	            snake.head.x--;
	        }
	        else{
	            snake.head.x=79;
	            }
	        shift();
	        gotoxy(snake.tail.x,snake.tail.y);
	        		printf(" ");   // instead of cls
	        snake.tail = snake.snake_array[0];
	        return ;
	    }
	    if (direction == RIGHT && snake.direction != LEFT ){
	        snake.snake_array[snake.length - 1 ] = snake.head ;
	        if (snake.head.x<79){
	            snake.head.x++;
	        }
	        else{
	            snake.head.x = 0 ;
	            }
	        shift();
	        gotoxy(snake.tail.x,snake.tail.y);
	                  printf(" ");   // instead of cls
	        snake.tail = snake.snake_array[0];
	        return ;
	    }
	    return ;
	}

	void add_lenght(void){

	    snake.length=snake.length + 1;
	}

	void food(void){

	    int t ,a;
	    srand ( (unsigned)time ( NULL ) );
	    t=(rand())%80;
	    a=(rand())%25;
	    while((snake.head.x)!=t && (snake.head.y)!=a){
	        gotoxy(t,a);
		//speed(100);
		//Sleep(1000);
	        printf ("0");

	        return;
	    }
	    if ((snake.head.x)==t && (snake.head.y)==a){
	        t=(rand())%80;
	        a=(rand())%25;
	        gotoxy(t,a);
	        add_lenght();
	        return;
	    }
	}
	int randomvalue (int starting, int ending) // Return a random int value between end and starting parameters
	{
		int i;
		static int previous = 0;
		int answer;
		if (previous <0)
			previous = 0;
		int difference = starting - ending;
		time_t t;
		srand((unsigned) time(&t));
		for (i = 0; i <previous; i++) rand ();
		answer = (rand () % difference);
		previous++;
		return answer;
	}

	void gamephysics ()
	{
		static int foodcount = 0;//Keep Count of food
		int futurex, futurey, futurepixel;
		char scorestring [100];
		if (foodcount < 500) //Adds a food if no food is present and upto maximum 500 food
		{
			int valid = 0;
			int foodx;
			int foody;
			while (!valid)
			{
				foodx = randomvalue (15,1003);
				foody = randomvalue (15,695);

					foodcount++;
					valid = 1;
				}

			}
		}

/**************************************** ONE PLAYER **************************************************/

void one_player(){

	    int d,flag,dtmp ;
	    snakeCreation();
	    system("cls");
	    snake.direction = RIGHT ;//harkate aval

	    setcolor(13);
	    snakeDraw(snake);    // 4 what??????????????????????????????

	    d = COUNTINUE ;
	    while(d != EXIT )
	    {
	        Sleep(100);
	        flag = 0 ;
	        if (kbhit()){
	            dtmp = d ;
	            d = getInput();
	            if (d == COUNTINUE)
	                d = dtmp ;//for kelid gheir az jahat ha
	            flag = 1;
	            }
	        //snake1
	        if (d == UP && snake.direction == DOWN ){
	            d = DOWN ;
	            flag = 0 ;
	        }
	        if (d == DOWN && snake.direction == UP ){
	            d = UP ;
	            flag = 0 ;
	        }
	        if (d == LEFT && snake.direction == RIGHT ){
	            d = RIGHT ;
	            flag = 0 ;
	        }
	        if (d == RIGHT && snake.direction == LEFT ){
	            d = LEFT ;
	            flag = 0 ;
	        }
	        if (flag == 1 ){
	            snake.direction = d ;
	            }


			moveSnake(d);

			setcolor(13);
			snakeDraw(snake);
			food();
		}
	}


//  -----------------------------------2--------------------------------------------------


void shift1(){
    int i;
    int snake,length,snake_array;
    int snake1;
        for (i = 0 ; i < snake1.length - 1 ; i++ ){
        snake1.snake_array[i] = snake1.snake_array[i+1] ;
        }
    }

void wall()
{
	//9 sormee, 18 sormee por, 49bahale ,412 khube :D/>/> 666the best, 77ham best:D
	setcolor(666);
	int i;
	gotoxy(0,0);
	printf(" --------------------------------------------------------");
	gotoxy(0,24);
	printf(" --------------------------------------------------------");

	for(i=1;i<24;i++){
		gotoxy(56,i);
		printf("|");
	}
	for(i=1;i<24;i++){
		gotoxy(0,i);
		printf("|");
	}
	gotoxy(60,9);
	setcolor(13);
	printf("score snake1:");

}


int getInput2()
{
    char c ;
    int arrow,arrow2;
    arrow = getch ();
    if(arrow=='w')
    	return UP1;
    if(arrow=='d')
    	return RIGHT1;
    if(arrow=='a')
    	return LEFT1;
    if(arrow=='s')
    	return DOWN1;

    if(arrow==224)
    {
        arrow2 = getch ();
        if(arrow2==72)
            return UP ;
        else if(arrow2==80)
            return DOWN;
        else if(arrow2==75)
            return LEFT ;
        else if(arrow2==77)
            return RIGHT ;
    }
    if (arrow == 27 )
    {
        system("cls");
        setcolor(666);
        gotoxy(30,10);
        printf("DO YOU WANT TO EXIT ?");
        gotoxy(36,11);
        printf(" Y / N ");
        c = getch();
        if (c == 'y' || c == 'Y'){
            return EXIT ;
            }
        else if (c == 'N' || c == 'n'){
        	system("cls");
        	//wall();
            return COUNTINUE ;
        	}
        return 0;
    }
    else
    	return COUNTINUE ;
}
void moveSnake1(int direction)
{
	//snake1
	char snake;
    if (direction == DOWN && snake1.direction != UP ){
        snake1.snake_array[snake1.length - 1 ] = snake1.head ;
        if (snake1.head.y<23){
        snake1.head.y++;
        }
        else{
            snake1.head.y = 1 ;
            }

        shift1();
        gotoxy(snake1.tail.x,snake1.tail.y);
            printf(" ");  // instead of cls
        snake1.tail = snake1.snake_array[0];
        return ;
    }

    if (direction == UP && snake1.direction != DOWN ){
        snake1.snake_array[snake1.length - 1 ] = snake1.head ;
        if (snake1.head.y>1){
            snake1.head.y--;
        }
        else {
            snake1.head.y = 23 ;
            }
        shift1();
        gotoxy(snake1.tail.x,snake1.tail.y);
                   printf(" ");   // instead of cls
        snake1.tail = snake1.snake_array[0];
        return ;
    }
    if (direction == LEFT && snake1.direction != RIGHT ){
        snake1.snake_array[snake1.length - 1 ] = snake1.head ;
        if (snake1.head.x>1 ){
            snake1.head.x--;
        }
        else{
            snake1.head.x=55;
            }
        shift1();
        gotoxy(snake1.tail.x,snake1.tail.y);
        		printf(" ");   // instead of cls
        snake1.tail = snake1.snake_array[0];
        return ;
    }
    if (direction == RIGHT && snake1.direction != LEFT ){
        snake1.snake_array[snake1.length - 1 ] = snake1.head ;
        if (snake1.head.x<55){
            snake1.head.x++;
        }
        else{
            snake1.head.x = 1 ;
            }
        shift1();
        gotoxy(snake1.tail.x,snake1.tail.y);
                  printf(" ");   // instead of cls
        snake1.tail = snake1.snake_array[0];
        return ;
    }
    return ;
}
static int score1;
static int score2;
int win(){
	int i=0, j=0;
	//snake1


	//snake 1 b khodesh bokhore score2 ziad mishe :D/>/>
	char snake1,length;
	while(j!=(snake1.length-2))
	{
	    char head;
		if(snake1.head.x == snake1.snake_array[j].x && snake1.head.y == snake1.snake_array[j].y){
			score2++;
			if(score2==20)
				return 2;
			}
		j++;
	}
	if(snake1.head.x==snake1.tail.x && snake1.head.y==snake1.tail.y)
			score2++;
	if(score2==20)
		return 2;


	//snake1
	setcolor(13);
	gotoxy(74,9);
	printf("%d",score1);


        //snake1
        int d1,flag;
        if (d1 == UP && snake1.direction == DOWN ){
            d1 = DOWN ;
            flag = 0 ;
        }
        if (d1 == DOWN && snake1.direction == UP ){
            d1 = UP ;
            flag = 0 ;
        }
        if (d1 == LEFT && snake1.direction == RIGHT ){
            d1 = RIGHT ;
            flag = 0 ;
        }
        if (d1 == RIGHT && snake1.direction == LEFT ){
            d1 = LEFT ;
            flag = 0 ;
        }
            if (flag == 1 ){
            snake1.direction = d1 ;
                }

        moveSnake1(d1);


        setcolor(13);
        snakeDraw(snake1);


        setcolor(11);


//-------------------------------aaaaaaaaiiiiiiiii-----------------------------------------


int distance (int x2,int y2,int x1,int y1)
{//yadet bashe :D/>/> lu
int x1,x2,y1,y2;
	if(x2==56)
		x2=1;
	if(x2==0)
		x2=55;
	if(y2==24)
		y2=1;
	if(y2==0)
		y2=23;

	return sqrt(pow((x2 - x1),2) + pow((y2 - y1),2));
}


;
int menu()
{
	//int which;
	int line = 1;
	int c,arrow;
	int x=10;
		setcolor(12);
	gotoxy(30,x+2);
	printf("  1-player   ");




	while((c=getch())!= 'a' ){
	    if(c==224)
	    {
	        arrow = getch ();
	        if(arrow==72){
	        	if(line==1){

		            gotoxy(30,x+2);
		            setcolor(12);
		            printf("  1-player   ");

		            line=3;

	        	}
	        	else if (line==2){

		            gotoxy(30,x+2);
		            setcolor(12);
		            printf("  1-player   ");

		            line=1;

	            }
	        	else if(line==3){
	        			            gotoxy(30,x+2);
		            setcolor(380);
		            printf("  1-player   ");

		            line=2;
	        	}
	        }
	        else if(arrow==80){
	        	if(line==1){

		            gotoxy(30,x+2);
		            setcolor(380);
		            printf("  1-player   ");

		            line=2;

		        	}
	        	else if(line==2){

		            gotoxy(30,x+2);
		            setcolor(12);
		            printf("  1-player   ");

		            line=3;
	        	}
	        	else if(line==3){

		            gotoxy(30,x+2);
		            setcolor(12);
		            printf("  1-player   ");

		            line=1;
	        	}
	        }
	      }
	    }
	return line ;
}

int main(){
	int menu1 ;
	menu1 = menu();
	system("cls");
	gotoxy(0,0);


	if (menu1 == 2 ){
		printf("2");
		one_player();
	}
	int ai_snake;
	if (menu1 == 3 ){
		ai_snake();
	}
	return 0;
}

This post has been edited by jimblumberg: 03 February 2013 - 07:04 AM
Reason for edit:: Added missing code tags. Please learn to use them properly.

Was This Post Helpful? 0
  • +
  • -

#5 hamidooooo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 02-February 13

Re: error "length" is not a type!

Posted 03 February 2013 - 06:29 AM

line 5 turns into smilies so i correct it :



#define max3 ( a , b , c ) ( ( a ) > = ( b ) ? ( ( a ) > ( c ) ? ( a ) : ( c ) ) : ( ( b ) > ( c ) ? ( b ) : ( c ) ) )

This post has been edited by jimblumberg: 03 February 2013 - 07:05 AM
Reason for edit:: Added missing code tags. Please learn to use them properly.

Was This Post Helpful? 0
  • +
  • -

#6 jimblumberg  Icon User is offline

  • member icon


Reputation: 4074
  • View blog
  • Posts: 12,573
  • Joined: 25-December 09

Re: error "length" is not a type!

Posted 03 February 2013 - 07:06 AM

If you have compile errors please post the complete error messages exactly as they appear in your development environment.


And in future please use code tags when posting code!

:code:



Jim
Was This Post Helpful? 0
  • +
  • -

#7 undefined behaviour  Icon User is offline

  • New D.I.C Head

Reputation: 7
  • View blog
  • Posts: 36
  • Joined: 17-January 13

Re: error "length" is not a type!

Posted 03 February 2013 - 07:16 AM

Did you notice the background of the textbox you wrote your message into, telling you to "Please put [code] tags [/code] around your code!"?

Did you notice it also says "Don't tell us to give you code! We won't do your homework for you. Tell us what errors you're getting. Tell us what you've tried/searched for"?

No. I'm waiting quite patiently for these requests to be fulfilled. Let me know when you actually want help.
Was This Post Helpful? 0
  • +
  • -

#8 hamidooooo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 02-February 13

Re: error "length" is not a type!

Posted 03 February 2013 - 07:32 AM

im very sorry.im new here and dont know the rules yet.i will do what u said next time.and i dont want u to do my homework.i have some errors and dont know how to fix them.
"""""
In function `void shift1()':
324: error: `length' is not a type
error: request for member of non-aggregate type before '-' token
error: `snake_array' is not a type
error: request for member of non-aggregate type before '[' token
error: `snake_array' is not a type
error: request for member of non-aggregate type before '[' token
In function `void moveSnake1(int)':
error: `snake1' undeclared (first use this function)
error: (Each undeclared identifier is reported only once for each function it appears in.)
In function `int win()':
error: `length' is not a type
error: request for member of non-aggregate type before '-' token
error: `head' is not a type
error: request for member of non-aggregate type before '.' token
error: `snake_array' has not been declared
error: request for member of non-aggregate type before '[' token
error: `head' is not a type
error: request for member of non-aggregate type before '.' token
error: `snake_array' has not been declared
error: request for member of non-aggregate type before '[' token
error: `head' has not been declared
error: request for member of non-aggregate type before '.' token
error: `tail' has not been declared
error: request for member of non-aggregate type before '.' token
error: request for member of non-aggregate type before '.' token
error: `tail' has not been declared
error: request for member of non-aggregate type before '.' token
error: `direction' has not been declared
error: request for member of non-aggregate type before '==' token
error: `direction' has not been declared
error: request for member of non-aggregate type before '==' token
error: `direction' has not been declared
error: request for member of non-aggregate type before '==' token
error: `direction' has not been declared
error: request for member of non-aggregate type before '==' token
error: `direction' has not been declared
error: request for member of non-aggregate type before '=' token
error: conversion from `char' to non-scalar type `snake_data' requested
error: a function-definition is not allowed here before '{' token
error: expected `,' or `;' before '{' token
error: expected primary-expression before "int"
error: expected `;' before "int"
error: expected primary-expression before "int"
error: expected `;' before "int"
error: expected `}' at end of input
"""""

most of them are "is not a type error" and i think somthing isnt right about my structure.i tried to fix this and put a "snake" struct" in it and i have got some new errors!!!!

C:\Users\movie\Desktop\main.cpp: In function `void shift1()':
C:\Users\movie\Desktop\main.cpp:324: error: `length' is not a type
C:\Users\movie\Desktop\main.cpp:324: error: request for member of non-aggregate type before '-' token
C:\Users\movie\Desktop\main.cpp:325: error: `snake_array' is not a type
C:\Users\movie\Desktop\main.cpp:325: error: request for member of non-aggregate type before '[' token
C:\Users\movie\Desktop\main.cpp:325: error: `snake_array' is not a type
C:\Users\movie\Desktop\main.cpp:325: error: request for member of non-aggregate type before '[' token

C:\Users\movie\Desktop\main.cpp: In function `void moveSnake1(int)':
C:\Users\movie\Desktop\main.cpp:406: error: `snake1' undeclared (first use this function)
C:\Users\movie\Desktop\main.cpp:406: error: (Each undeclared identifier is reported only once for each function it appears in.)

C:\Users\movie\Desktop\main.cpp: In function `int win()':
C:\Users\movie\Desktop\main.cpp:475: error: `length' is not a type
C:\Users\movie\Desktop\main.cpp:475: error: request for member of non-aggregate type before '-' token
C:\Users\movie\Desktop\main.cpp:478: error: `head' is not a type
C:\Users\movie\Desktop\main.cpp:478: error: request for member of non-aggregate type before '.' token
C:\Users\movie\Desktop\main.cpp:478: error: `snake_array' has not been declared

C:\Users\movie\Desktop\main.cpp:478: error: request for member of non-aggregate type before '[' token
C:\Users\movie\Desktop\main.cpp:478: error: `head' is not a type
C:\Users\movie\Desktop\main.cpp:478: error: request for member of non-aggregate type before '.' token

C:\Users\movie\Desktop\main.cpp:478: error: `snake_array' has not been declared
C:\Users\movie\Desktop\main.cpp:478: error: request for member of non-aggregate type before '[' token
C:\Users\movie\Desktop\main.cpp:485: error: `head' has not been declared
C:\Users\movie\Desktop\main.cpp:485: error: request for member of non-aggregate type before '.' token
C:\Users\movie\Desktop\main.cpp:485: error: `tail' has not been declared
C:\Users\movie\Desktop\main.cpp:485: error: request for member of non-aggregate type before '.' token
C:\Users\movie\Desktop\main.cpp:485: error: `head' has not been declared
C:\Users\movie\Desktop\main.cpp:485: error: request for member of non-aggregate type before '.' token
C:\Users\movie\Desktop\main.cpp:485: error: `tail' has not been declared
C:\Users\movie\Desktop\main.cpp:485: error: request for member of non-aggregate type before '.' token
C:\Users\movie\Desktop\main.cpp:499: error: `direction' has not been declared
C:\Users\movie\Desktop\main.cpp:499: error: request for member of non-aggregate type before '==' token
C:\Users\movie\Desktop\main.cpp:503: error: `direction' has not been declared
C:\Users\movie\Desktop\main.cpp:503: error: request for member of non-aggregate type before '==' token
C:\Users\movie\Desktop\main.cpp:507: error: `direction' has not been declared
C:\Users\movie\Desktop\main.cpp:507: error: request for member of non-aggregate type before '==' token
C:\Users\movie\Desktop\main.cpp:511: error: `direction' has not been declared

C:\Users\movie\Desktop\main.cpp:511: error: request for member of non-aggregate type before '==' token
C:\Users\movie\Desktop\main.cpp:516: error: `direction' has not been declared
C:\Users\movie\Desktop\main.cpp:516: error: request for member of non-aggregate type before '=' token
C:\Users\movie\Desktop\main.cpp:523: error: conversion from `char' to non-scalar type `snake_data' requested
C:\Users\movie\Desktop\main.cpp:533: error: a function-definition is not allowed here before '{' token
C:\Users\movie\Desktop\main.cpp:533: error: expected `,' or `;' before '{' token
C:\Users\movie\Desktop\main.cpp:549: error: expected primary-expression before "int"
C:\Users\movie\Desktop\main.cpp:549: error: expected `;' before "int"
C:\Users\movie\Desktop\main.cpp:625: error: expected primary-expression before "int"
C:\Users\movie\Desktop\main.cpp:625: error: expected `;' before "int"

C:\Users\movie\Desktop\main.cpp:641: error: expected `}' at end of input
Was This Post Helpful? 0
  • +
  • -

#9 jimblumberg  Icon User is offline

  • member icon


Reputation: 4074
  • View blog
  • Posts: 12,573
  • Joined: 25-December 09

Re: error "length" is not a type!

Posted 03 February 2013 - 07:50 AM

Please don't create new topics for an existing problem. You already have an open topic so use that. Topics merged.


For the first problem start by looking at the function where your error message told you it detected the problem, namely

Quote

In function `void shift1()':

Now the function in question:
void shift1(){
    int i;
    int snake,length,snake_array;
    int snake1;
        for (i = 0 ; i < snake1.length - 1 ; i++ ){
        snake1.snake_array[i] = snake1.snake_array[i+1] ;
        }
    }


Look closely at your variable definitions, snake1 in particular

Then re-examine your error message:

Quote

error: `length' is not a type
error: request for member of non-aggregate type before '-' token
error: `snake_array' is not a type
error: request for member of non-aggregate type before '[' token
error: `snake_array' is not a type
error: request for member of non-aggregate type before '[' token


First what type of variable is snake1? Is it a structure, a double, a char, or is is maybe a simple int?

Next look at snake_array is that variable actually an array? Or is it possible that it is just a single int?

You seem to be using global variables, which is a bad practice by the way, and then naming local variables the same as those global variables. Doing this hides the global instance and uses the local instances. This seems to be one of your big problems, that and you don't yet seem to have a grasp of the different type of variables.


But the biggest problem seems to be that you waited much too long to compile your program. By waiting so long you have created quite a few problems that you must try to fix. If you compile your program after adding just a couple of lines of code then your number of errors will be much less and you will know exactly where to start looking for the problems.


I suggest you revisit your class notes, textbook and other sources for information on how to properly use structures. This seems to be your biggest problem, you don't understand how structures work. Also you may want to learn how to properly pass variables to and from your functions, to eliminate the global variables. The function tutorials contained in my signature may help with learning to properly use functions.



Jim

This post has been edited by jimblumberg: 03 February 2013 - 07:51 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1