Thread: help me

  1. #1
    Registered User
    Join Date
    May 2010

    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.

    # 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;
    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

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


  3. #3
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    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
    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
    The edge of the known universe
    So why did you point at the second error, when you skipped the first?

    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