Printing Array help

This is a discussion on Printing Array help within the C Programming forums, part of the General Programming Boards category; Originally Posted by joeprogrammer Read this . I don't think you're supposed to post your entire assignment. If you have ...

  1. #16
    Registered User
    Join Date
    Feb 2006
    Posts
    63
    Quote Originally Posted by joeprogrammer
    Read this. I don't think you're supposed to post your entire assignment. If you have problems, program crashing, etc. don't be afraid to ask. But what's the point of a homework assignment if other people do it for you?
    Yeah, I dont want people doing it for me. I am working through it, and when I come up to something I just cant get to work, I ask for help. The only reason I posted the assignment is because people werent understanding what I was trying to do.

  2. #17
    Registered User
    Join Date
    Feb 2006
    Posts
    63
    Ok, I think I am doing this right. How do I get it to print the new array after I have changed the element to the guest initial?

    EDIT: Also I know that I am probably not doing this the best way possible, but I have to do it the way I know how, I want to understand what I am doing, and this is just the way I work it out.

    This is what I have:

    Code:
    #include <stdio.h>
    #define ROWS 4
    #define COLUMNS 2
    
    #include <stdio.h>
    
    void printArray(int a[][2]);
    void modifyElement(int e, char guest);
    
    int main()
    {
    	int table[ROWS][COLUMNS]={1,2,3,4,5,6,7,8};
    	int seat;
    	int r;
    	int c;
    	char guest, junkChar;
    
    	printArray(table);
        getchar();
    
    	printf("In which seat would you like to place a guest?\n");
    	scanf("%d",&seat);
    
    	scanf("%c",&junkChar);
    	printf("What is the initial of the guest you would like to place in this seat?\n");
    	scanf("%c",&guest);
    
    	switch(seat){
    	case 1:
    		r=0;c=0;
    		break;
    	
    	case 2:
    		r=0;c=1;
    		break;
    	
    	case 3:
    		r=1;c=0;
    		break;
    	
    	case 4:
    		r=1;c=1;
    		break;
    	
    	case 5:
    		r=2;c=0;
    		break;
    
    	case 6: 
    		r=2;c=1;
    		break;
    
    	case 7:
    		r=3;c=0;
    		break;
    
    	case 8:
    		r=3;c=1;
    		break;
    
    	default:
    		printf("You have entered an invalid seat number, please restart program.\n");
    
    		return 0;
    		break;
    	}
    	
    	modifyElement(table[r][c],guest);
    
    	
    	return 0;
    
    }
    
    void printArray(int a[][2])
    {
    	int i;
    	int j;
        printf("\t_____U____\n");
    	for(i=0;i<=3;i++) {
    
    		for(j=0;j<=1;j+=2){
    			printf("\t%d|\t|%d\n",a[i][j],a[i][j+1]);
    		}
    
    	}
    	printf(" \t----------\n");
    }
    
    void modifyElement(int e, char guest)
    {
    	
    	e = guest;
    	
    }
    Last edited by saahmed; 02-22-2006 at 08:13 PM.

  3. #18
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well modifyElement doesn't actually do anything. Both items are passed by value, so in effect, nothing at all happens. You'll probably want to use pointers. Although I'm not really sure what it is you're trying to do with that function.


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #19
    Registered User
    Join Date
    Feb 2006
    Posts
    63
    Quote Originally Posted by quzah
    Well modifyElement doesn't actually do anything. Both items are passed by value, so in effect, nothing at all happens. You'll probably want to use pointers. Although I'm not really sure what it is you're trying to do with that function.


    Quzah.
    Yeah, I see that nothing is actually happening, all I really did was set e to the entered character. The function is supposed to modify the chosen element. (The seat number needs to be changed to the guest's initial).

    Also, dont think I need to use pointers, as that is in the next chapter.
    Last edited by saahmed; 02-22-2006 at 10:15 PM.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. printing half a char array
    By theoneandonly in forum C Programming
    Replies: 19
    Last Post: 11-11-2006, 06:27 AM
  2. Replies: 3
    Last Post: 11-03-2003, 07:55 PM
  3. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  4. Array Program
    By emmx in forum C Programming
    Replies: 3
    Last Post: 08-31-2003, 12:44 AM
  5. Printing an integer stored in an array
    By Freez3L in forum C Programming
    Replies: 4
    Last Post: 11-18-2002, 01:11 AM

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