Thread: Am I interpreting this correctly?

  1. #1
    Registered User SCRIPT_KITTEH's Avatar
    Join Date
    Apr 2013
    Posts
    74

    Question Am I interpreting this correctly?

    Hi folks,

    I have an end of chapter question here, that I believe I have solved, but am not sure if I've understood the question correctly in the first place. What do you think this question is asking?

    Devise a function chline(ch, i, j) that prints the requested character in columns i through j. Test it in a simple driver.
    I interpreted that to mean the user inputting a character, and then the program makes two columns, printing the character i times in the first column & j times in the second column. I came up with this (tested and works a la my interpretation):

    Code:
    /* exercise 2 in chapter 9 */
    
    
    #include <stdio.h>
    void chline(char x, int y, int z);
    char get_first(void);
    int get_int(void);
    int main(void)
    {
        char x;
        int y, z;
    
    
        printf("\nPlease enter a character: ");    
        x = get_first();
        
        printf("\nNow please enter integer for column x: ");
        y = get_int();
        
        printf("\nNow please enter integer for column y: ");
        z = get_int();
    
    
        chline(x, y, z);
    
    
        return 0;
    }
    
    
    void chline(char x, int y, int z)
    {
        int i;
        
        printf("\n\tx\t\ty\n");
        printf("\t\b---\t\t\b---\n");
        
        for(i = 0; (i < y) || (i < z); i++)
        {
            if((i < y) && (i < z))
                printf("\t%c\t\t%c\n", x, x);
            else if((i < y) && (i >= z))
                printf("\t%c\n",x);
            else
                printf("\t \t\t%c\n", x);
        }
    }
    
    
    char get_first(void)
    {
            int ch;
    
    
            ch = getchar();
            while(getchar() != '\n')
                    continue;
    
    
            return ch;
    }
    
    
    int get_int(void)
    {
            int input;
            char ch;
    
    
            while (scanf("%d", &input) != 1)
            {
                    while((ch = getchar()) != '\n')
                            printf("\n");
                            putchar(ch);
                    printf(" is not an integer.\nPlease inter an ");
                    printf("integer value, such as 25, -178 or 3:");
            }
    
    
            while(getchar() != '\n')
                    continue;
    
    
            return input;
    }
    Do you think this is good or am I barkin' up the wrong tree?

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Yeah, Woof! Woof!

    The statement refers to columns i through j, the parameter values for the function. Your program should print the user's char (ch), one time, in each column, i through j, inclusive. So if i was 2 and j was 4, and ch was X, it would look like:

    Code:
    columns 1 2 3 4 5 6 7
            ============
              X X X
    Last edited by Adak; 08-03-2013 at 06:16 PM.

  3. #3
    Registered User SCRIPT_KITTEH's Avatar
    Join Date
    Apr 2013
    Posts
    74
    Quote Originally Posted by Adak View Post
    Yeah, Woof! Woof!

    The statement refers to columns i through j, the parameter values for the function. Your program should print the user's char (ch), one time, in each column, i through j, inclusive. So if i was 2 and j was 4, and ch was X, it would look like:

    Code:
    columns 1 2 3 4 5 6 7
            ============
              X X X

    Ohh, I see! That makes a lot more sense, thank you!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble Interpreting Column Headers
    By jwroblewski44 in forum C Programming
    Replies: 23
    Last Post: 03-11-2013, 07:19 PM
  2. interpreting fcnrl F_GETFL
    By MK27 in forum C Programming
    Replies: 8
    Last Post: 10-08-2008, 09:42 AM
  3. Help interpreting error message:
    By Karmachrome in forum C Programming
    Replies: 2
    Last Post: 12-11-2005, 04:13 AM
  4. interpreting xml
    By WebmasterMattD in forum C++ Programming
    Replies: 3
    Last Post: 09-07-2003, 08:20 AM
  5. interpreting time fields in a structure
    By *ClownPimp* in forum C++ Programming
    Replies: 2
    Last Post: 01-14-2003, 12:07 PM