Thread: help me

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    9

    help me

    i am doing some stuff on image processing on c++. unfortunately i am getting a problem with 2d arrays. i have consulted internet and found how to use 2d arrays properly but still getting the error. i am pasting my code, highlighting the error in red.
    thanx

    Code:
    # include <stdio.h>
    # include <iostream>
    using std :: cout;
    using std :: endl;
    void main ()
    {
    	int ch;
    	int i;
    	unsigned int h[50], filesize, width,height, validity, bpp, sod, h[2000][2000], col, row ;
    	FILE *fp;
    	fp= fopen ("c:\\lena512.bmp", "r");               ///ADDRESS OF FILE.
    		if (fp == NULL)
    			puts("not possible");
    		
    //while((ch = fgetc(fp)) != EOF)
      
    		for (i=0; i<=30; i++)
    		{
    			ch = fgetc(fp);
            h[i]= ch;
    		}
    validity= h[0] + 256*h[1];
    if (validity== 19778)
    	cout << "                                it is a valid BITMAP FILE "<<endl<<endl<<endl;
    filesize= h[2]+ 256*h[3]+ 256*256*h[4]+ 256*256*256*h[5];
    cout<< "FILE SIZE *****************************   "<< filesize << " bytes"<<endl<<endl<<endl;
    width= h[18] + 256*h[19] + 65536*h[20] + 16777216*h[21];
    height= h[22]+ 256*h[23]+ 65536*h[24]+ 16777216*h[25];
    cout<< "DIMENSIONS(wid x hei) *****************   "<< width <<" x "<< height<< endl<<endl;
    bpp= h[28]+ 256*h[29];
    if (bpp==1)
    	cout << "monochromatic";
    	if (bpp==4)
    		cout<< "16colour";
    		if (bpp==8)
    			cout<< "256colour";
    			if (bpp==16)
    				cout<< "64k colour";
    				if (bpp==24)
    					cout<< "16million colour";
    sod  = h[10] + 256*h[11]+ 65536*h[12]+ 16777216*h[13];
    cout <<endl<< "sod"<< sod;
    fclose(fp);
    cout << endl<<"end";
    for (row=sod; row<=width; row++)
    	for(col=0; col<=height; col++)
    	{
    		ch = fgetc(fp);
    		h[row][col]= ch; error:subscript requires array or pointer type
    	}
    while(1);
    
    }

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    I do so love the shotgun approach.

    Soma

  3. #3
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    431
    Code:
    unsigned int h[50], filesize, width,height, validity, bpp, sod, h[2000][2000], col, row ;
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    9
    oh my god. i am so dummy........ using a same name for two arrays.
    anyway thanks

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    So why did you point at the second error, when you skipped the first?

    Code:
    foo.cpp:5: error: ‘::main’ must return ‘int’
    foo.cpp: In function ‘int main()’:
    foo.cpp:10: error: conflicting declaration ‘unsigned int h [2000][2000]’
    foo.cpp:9: error: ‘h’ has a previous declaration as ‘unsigned int h [50]’
    foo.cpp:53: error: invalid types ‘unsigned int[unsigned int]’ for array subscript
    You had an error message in front of you, but decided to post the second one instead.
    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.

Popular pages Recent additions subscribe to a feed