kindly help

This is a discussion on kindly help within the C Programming forums, part of the General Programming Boards category; i am doing an image processing code in c++ 2010. but i am getting an error in the 2d arrays. ...

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

    kindly help

    i am doing an image processing code in c++ 2010. but i am getting an error in the 2d arrays. kindly help me. i am pasting my code here. and high lighting the place where the error is. thanx in advance

    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]= 2;  error: subscript requires array or pointer type
    	}
    while(1);
    
    }

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Quote Originally Posted by Omer View Post
    i am doing an image processing code in c++ 2010. but i am getting an error in the 2d arrays. kindly help me. i am pasting my code here. and high lighting the place where the error is. thanx in advance

    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]= 2;  error: subscript requires array or pointer type
    	}
    while(1);
    
    }
    1) there is no such thing as C++ 2010.

    2) This is a C forum not a C++ forum
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    9
    c++ and c are almost the same. kindly tell me waht is the prob in 2d array if u can

  4. #4
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Quote Originally Posted by Omer View Post
    c++ and c are almost the same. kindly tell me waht is the prob in 2d array if u can
    No they are not. Also, I have no idea what you problem is. You should post this to the C++ forum.

    Actually, your problem is that h is an array.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    9
    why cant i be able to do h[row][col]=2;

  6. #6
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Because h is an array.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    9
    i know it is an array as i have declared it as an array. but if i write h[row][col]=2 in the for loop. it should go like this
    h[0][0]=2
    h[0][1]=2
    h[0][2]=2
    isnt it

  8. #8
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    An array is a unidimensional data structure.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  9. #9
    Registered User sandeep080's Avatar
    Join Date
    Apr 2010
    Posts
    17
    Quote Originally Posted by Omer View Post
    i know it is an array as i have declared it as an array. but if i write h[row][col]=2 in the for loop. it should go like this
    h[0][0]=2
    h[0][1]=2
    h[0][2]=2
    isnt it
    for that you need to put it this way:
    Example:
    Code:
    h[2][3]= {
                   {2,2},
                   {2,2},
                   {2,2}
                   };
    Its just one of the various methods to initialise..
    simply
    Code:
    h[2][3]=2;
    doesn't work

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Kindly Help me with the ERRORS!!
    By Fatima Rizwan in forum C++ Programming
    Replies: 2
    Last Post: 11-11-2009, 11:28 AM
  2. Kindly help!!!
    By Fatima Rizwan in forum C++ Programming
    Replies: 5
    Last Post: 03-22-2009, 07:17 PM
  3. Kindly Explain the reason behind this?
    By chottachatri in forum C++ Programming
    Replies: 3
    Last Post: 02-24-2008, 09:10 AM
  4. C program - Kindly help
    By psriram in forum C Programming
    Replies: 2
    Last Post: 12-30-2007, 08:08 AM
  5. Replies: 18
    Last Post: 06-14-2003, 10:40 AM

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