Thread: Pointers trouble

  1. #16
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    try:
    gotoxy(r,c);
    printf("*");

  2. #17
    Registered User
    Join Date
    Feb 2006
    Posts
    63
    does it have anything to do with storing the memory location?

  3. #18
    Registered User
    Join Date
    Feb 2006
    Posts
    63
    Quote Originally Posted by qqqqxxxx
    try:
    gotoxy(r,c);
    printf("*");
    While that may work, I dont think I can really use it because I havent learned anything like that. But i'll look through the book quick and see if it is anywhere, then I could use it.

    EDIT: actually I just remembered at the beginning of the semester they said we could not use goto statements.

  4. #19
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    gotoxy can be used for positioning the cursor at (r,c)
    but it is non standard.

  5. #20
    Registered User
    Join Date
    Feb 2006
    Posts
    63
    Quote Originally Posted by qqqqxxxx
    gotoxy can be used for positioning the cursor at (r,c)
    but it is non standard.
    do you think there is any other way to do it?

    This is what I got, I know its wrong, but is there something I could change to make it work?

    Code:
    int size=0;
    
    	for(r=0;r<25;r++){
    		if(image[r]==1){
    			size++;
    		}
    	}
    
    	for (r = 0; r < size; r++)
    	{
    
    		for (c = 0; c < size; c++)
    		{  
    			if(image[r+c*size] == 1){
    				printf("*");
    			}
    		}
    	}

  6. #21
    Registered User
    Join Date
    Feb 2006
    Posts
    63
    I just wanted to get this straight because Im not so sure. The drawImage function is creating a square of 1s right? Because when I try out the program with the function I added, it just ends after asking for the size of square I want. Basically I think its implying that no element in the array equals 1 (in my printImage function).

    EDIT: if this helps this is all I have:
    Code:
    #include <stdio.h>
    #include "drawImage.h"
    
    /*function prototypes*/
    void printImage(int image[]);
    void edgeDetection(int image[], int edge[]);
    
    /*function main begins program execution*/
    int main (){
    	
    	int side;
    	int square[625];
    	int i, even;
    
    	printf("Please enter the size of the square you would like to draw"  
    			"\n(maximum size is 23):");  /*print statement*/
    	scanf("%d",&side);
    
    	for(i = 0; i < 625; i ++){
    		square[i] = 0;
    	}
    
    	even = (side & 1);
    
    	drawImage(square, 25, side, even);
    
    	printImage(square);
    
    	
    	if(side>23){
    		printf("The size of the square cannot be larger than 23, please start again\n");
    		
    		return 0;
    	} /*end if*/
    
    	return 0; /*indicate program ended successfully*/
    } /*end function main*/
    
    void printImage(int image[]){
    	int r, c;
    	int size=0;
    
    	for(r=0;r<25;r++){
    		if(image[r]==1){
    			size++;
    		}
    	}
    
    	for (r = 0; r < size; r++)
    	{
    
    		for (c = 0; c < size; c++)
    		{  
    			if(image[r+c*size] == 1){
    				printf("*");
    			}
    		}
    	}
    }

  7. #22
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    Code:
    int size=0;
    
    	for(r=0;r<25;r++){
    		if(image[r]==1){
    			size++;
    		}
    	}
    so when u use this size in the rest of your program,it doesnt traverse through the whole array.
    >printf("*");

    u wont get a square,because u have to set the cursor at the correct position first.

  8. #23
    Registered User
    Join Date
    Feb 2006
    Posts
    63
    Quote Originally Posted by qqqqxxxx
    Code:
    int size=0;
    
    	for(r=0;r<25;r++){
    		if(image[r]==1){
    			size++;
    		}
    	}


    so when u use this size in the rest of your program,it doesnt traverse through the whole array.
    Well here I am just trying to get the length of the square. I was thinking all I needed was the length of a side. Am I wrong?

  9. #24
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    the problem is u have still not understood the assignment well and neither have i.
    go through the drawimage function.
    make sure u understand what is going on inside it.

    then think of the printimage function.

    so,
    image array defines the canvas.
    and the square is loacted in the center of the canvas.
    Last edited by qqqqxxxx; 03-23-2006 at 03:17 AM.

  10. #25
    Registered User
    Join Date
    Feb 2006
    Posts
    63
    Quote Originally Posted by qqqqxxxx
    the problem is u have still not understood the assignment well.
    go through the drawimage function.
    make sure u understand what is going on inside it.

    then think of the printimage function.

    so,
    image array defines the canvas.
    and the square is loacted in the center of the canvas.
    This is true, I am not really understanding the assignment well. I think I understood the part about the canvas and the square being in the center of the canvas, but Im just not understanding how it really works and how my functions should work. I guess Ill just give it some more thought. Thanks for your help though.

  11. #26
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    int size=0;

    for(r=0;r<25;r++){
    if(image[r]==1){
    size++;
    }
    }

    Code:
    
    
    sorry, this will give u the side,but u already know the side.

  12. #27
    Registered User
    Join Date
    Feb 2006
    Posts
    63
    Quote Originally Posted by qqqqxxxx
    int size=0;

    for(r=0;r<25;r++){
    if(image[r]==1){
    size++;
    }
    }

    Code:
    
    
    sorry, this will give u the side,but u already know the side.
    but the side hasnt been passed on to this function. so this is needed right?

  13. #28
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    and i tried running your program,the printimage function is working.

  14. #29
    Registered User
    Join Date
    Feb 2006
    Posts
    63
    Quote Originally Posted by qqqqxxxx
    and run your program put a printf after the size calculation,see if u r gettin the side.
    well, no, the program is just ending after the user prompt to enter the desired size. This is why I was trying to understand drawImage better.

  15. #30
    Registered User
    Join Date
    Feb 2006
    Posts
    63
    Quote Originally Posted by qqqqxxxx
    and i tried running your program,the printimage function is working.
    Its working? When I enter the size I want, the program just ends without any warnings or anything. But, it doesnt print anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble with pointers..
    By elfjuice in forum C Programming
    Replies: 7
    Last Post: 11-25-2007, 01:19 AM
  2. function pointers
    By benhaldor in forum C Programming
    Replies: 4
    Last Post: 08-19-2007, 10:56 AM
  3. Replies: 4
    Last Post: 12-10-2006, 07:08 PM
  4. trouble with pointers HELP MEEEE???
    By drdodirty2002 in forum C++ Programming
    Replies: 1
    Last Post: 03-10-2004, 12:39 AM
  5. API "Clean Up" Functions & delete Pointers :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 05-10-2002, 06:53 PM