Results 1 to 3 of 3

Thread: what's wrong with this code?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    East Ballina,NSW,Australia
    Posts
    121

    Exclamation what's wrong with this code?

    Hi All,

    I just have a general question which i hope someone can solve for me.
    I'm trying to create a .a lib file, that passes paramters etc, but i keep getting a stupid compiler erro, can someone tell me what's wrong with this code?

    Code:
    #include <iostream.h>
    
    
    //The black Co-Ordinate
    char coutblack[8](int srow)
    {
    char cb[8];
    switch(srow)
    {
    case 0 : cb[8] = {' ' , ' ' , ' ' , ' ' , '|' , ' ' , ' ' , ' ' , ' ' }
    	break;
    case 1 : cb[8] = {' ' , ' ' , ' ' , '@' , '@' , '@' , ' ' , ' ' , ' ' }
    	break;
    case 2 : cb[8] = {' ' , ' ' , '@' , '@' , '@' , '@' , '@' , ' ' , ' ' }
    	break;
    case 3 : cb[8] = {'-' , '@' , '@' , '@' , '@' , '@' , '@' , '@' , '-' }
    	break;
    case 4 : cb[8] = {' ' , ' ' , '@' , '@' , '@' , '@' , '@' , ' ' , ' ' }
    	break;
    case 5 : cb[8] = {' ' , ' ' , ' ' , '@' , '@' , '@' , ' ' , ' ' , ' ' }
    	break;
    case 6 : cb[8] = {' ' , ' ' , ' ' , ' ' , '|' , ' ' , ' ' , ' ' , ' ' }
    	break;
    default: 
    	break;
    }
    return cb[8];
    }
    The goal of the code is to return the value of cb[8] based on whatever srow is inputed as i.e. 1 however, i keep getting a few stupid little errors any help would be greatly appreciated!

    Thanks

    Regards,

    Smithy.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You can't arbitrarily assign to arrays since they're stored as a single number representing a memory location (a pointer).
    A better idea would be something like:
    Code:
    #include <iostream.h>
    
    void coutblack(int srow, char *pcDest) {
    	static char ppcData[8][8] = {
    		{' ' , ' ' , ' ' , ' ' , '|' , ' ' , ' ' , ' ' , ' ' },
    		{' ' , ' ' , ' ' , '@' , '@' , '@' , ' ' , ' ' , ' ' },
    		{' ' , ' ' , '@' , '@' , '@' , '@' , '@' , ' ' , ' ' },
    		{'-' , '@' , '@' , '@' , '@' , '@' , '@' , '@' , '-' },
    		{' ' , ' ' , '@' , '@' , '@' , '@' , '@' , ' ' , ' ' },
    		{' ' , ' ' , ' ' , '@' , '@' , '@' , ' ' , ' ' , ' ' },
    		{' ' , ' ' , ' ' , ' ' , '|' , ' ' , ' ' , ' ' , ' ' }
    	};
    
    	memcpy(pcDest, ppcData[srow], 8);
    }
    
    void somecode() {
    	char pcData[8];
    	coutblack(3, pcData);
    }
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    East Ballina,NSW,Australia
    Posts
    121

    Smile thanks!

    Ok,

    Thanks for the advice!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width