Printing out a data table in different sequences

This is a discussion on Printing out a data table in different sequences within the C Programming forums, part of the General Programming Boards category; Hi - I am a beginning C student. My question is. I would like to print out seven different tables ...

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    1

    Question Printing out a data table in different sequences

    Hi -

    I am a beginning C student. My question is. I would like to print out seven different tables that are 7 x 7 using a "specific" list of 7 characters of A B C D E F G.

    I will sketch out what the first table will look like and then explain what the other tables will look like as well; it is a definite simple pattern I am looking to achieve.


    1 2 3 4 5 6 7

    A B C D E F G
    G A B C D E F
    F G A B C D E
    E F G A B C D
    D E F G A B C
    C D E F G A B
    B C D E F G A



    Notice how the letter A appears in the first horizontal row in position 1. Then in the row below it, "A" appears in position 2. Below this "A" is in position 3, ect. I want to be able to line up the "A"'s in a diagnal line from left to right.



    ... Then I want to do the SAME thing, only this time starting with the next character in the sequence of A-G ; this time it is B.

    B C D E F G A
    A B C D E F G
    G A B C D E F
    F G A B C D E
    E F G A B C D
    D E F G A B C
    C D E F G A B


    Ultimately I want to print out seven(7) different tables for each letter of: A, B, C, D, E, F, G .

    I would like to have this as a switch statement to choose each letter in the character set A-G. I know that I can just use printf() to do this but I am curious as to what the code would look like to use a "specific" list of characters that would take in the first character, build the first row, then build other rows using a different sequence.


    Thank you for taking my question and I hope you are having a great week .


    Best Regards,

    Brian

  2. #2
    Registered User moonwalker's Avatar
    Join Date
    Jul 2002
    Posts
    282
    Here it is... took about 15 darn minutes to figure out..
    as far as I know, you don't need a switch statement for this.

    The thing that I wrote also works with any number of letters..
    try changing myletters[] to "MOONWALKER"
    Code:
    #include <stdio.h>
    #include <string.h>
    
    int main()
    {
    	char myletters[] = "ABCDEFG";
    	unsigned int i, j, k, last;
    	
    	for (i = 0; i < strlen(myletters); i++)
    	{
    		last = i;
    		
    		for (j = i; j < strlen(myletters) + i; j++)
    		{
    			for (k = last; k < last + strlen(myletters); k++)
    			{
    				printf("%c", myletters[k % strlen(myletters)]);
    		
    			}
    			printf("\n");
    			last += strlen(myletters) -1;
    		}
    		printf("\n\n");
    	}
    		
    	
    			
    	return 0;
    }
    Good luck
    Last edited by moonwalker; 07-19-2003 at 11:48 PM.

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    913
    took me like 20-25, but mine was only good for one string.

    Code:
    int thingy(char string[]) {
        char *backup = malloc( strlen(string) + 1 );
            strcpy(backup, string);
        char *start = &string[6];
        int count = 2;
        
        printf("%s\n", string);
        
        while(count < 8) {
            backup[(8-count)] = '\0';
            printf("%s%s\n", start, backup);
        
            ++count;
            --start;
        }
        
        free(backup);
        
        return 0;
    }
    ill check your out more later, sleepy now...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 11:13 AM
  2. Replies: 4
    Last Post: 06-14-2005, 06:45 AM
  3. Inputting data from a table of properties
    By cassius in forum C Programming
    Replies: 1
    Last Post: 06-01-2005, 12:22 PM
  4. extra word printing
    By kashifk in forum C++ Programming
    Replies: 2
    Last Post: 10-25-2003, 05:03 PM
  5. problems reading data into an array and printing output
    By serino78 in forum C Programming
    Replies: 4
    Last Post: 04-28-2003, 09:39 AM

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