Thread: Printing Array help

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    63

    Printing and Modifying Array help

    My new problem:
    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;
    	
    }


    ORIGINAL POST (already figured out):
    How would I write a function to print an array that looks like this:

    __U__
    1| |2
    3| |4
    5| |6
    7|___|8

    I am able to get the array, but dont know how to get the lines.

    Thanks in advance for any input.

    EDIT: Its actually supposed to look like a rectangular table with columns 1,3,5,7 and 2,4,6,8. I dont know why I cant make it look right in this post.
    Last edited by saahmed; 02-22-2006 at 09:46 PM.

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, 07:27 AM
  2. Replies: 3
    Last Post: 11-03-2003, 08: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, 02:11 AM