Thread: CommandsProj2.Dat

  1. #1
    Registered User
    Join Date
    Dec 2014
    Location
    Miami, Florida, United States
    Posts
    19

    Red face CommandsProj2.Dat

    C Ch [Character Case Change ]
    Change character Ch to uppercase and print it outc Ch [Character Case Change]
    Change character Ch to lowercase and print it out
    P i k [Print k-th Digit ]
    Print out the k-th digit of integer i
    R x i [Round Reals ]
    Round double value x to i significant decimal places
    S x [Separate ]
    Separate out the sign, integer part and fractional part of double value x
    D i x [Partition Integer ]
    Given integers i and x, print out two integers j and k, where the sum of j and
    k equals i, and when you take x% of i and truncate it you get j
    H [Help ]
    Print a short synopsis of all the available commands
    Q [Quit ] Quit

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    And your question is ?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2014
    Location
    Miami, Florida, United States
    Posts
    19
    Quote Originally Posted by Salem View Post
    And your question is ?
    Exactly my response lol but how to do this i dont understand it... This program suppose to scan a text file and reads the file then prints the answer accordingly

    text file (.DAT)

    DA
    H
    + 3 5
    - 10 5
    * 8 9
    / 92 3
    c A
    C b
    P 56234 3
    R 3.14195 4
    S -51.235
    D 50 10
    Q

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Do you know how to open a file for reading? If not, read up on it and practice writing code that opens a file. (Be sure to check that the file opens successfully.)

    Do you know how to read from an opened file? If not, read up on it and practice writing code that reads from a text file. (Check by printing out what you've read from the file.)

    Do you know how to parse data from a string? If not, figure out how to check the contents of a string so you can process it as needed.

  5. #5
    Registered User
    Join Date
    Dec 2014
    Location
    Miami, Florida, United States
    Posts
    19
    Quote Originally Posted by Matticus View Post
    Do you know how to open a file for reading? If not, read up on it and practice writing code that opens a file. (Be sure to check that the file opens successfully.)

    Do you know how to read from an opened file? If not, read up on it and practice writing code that reads from a text file. (Check by printing out what you've read from the file.)

    Do you know how to parse data from a string? If not, figure out how to check the contents of a string so you can process it as needed.
    I could do this part but the rest I dont know like rounding and partitioning etc...

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #define LINE_MAXLENGTH 80
    
    
    
    
    int main()
    {
        float a, b;
        char operations;
    
    
        FILE* cmd = fopen("CommandsProj1.dat", "r");
    
    
    
    
        if (cmd == NULL)
        {
            printf("Error Code (404)");
            return EXIT_FAILURE;
        }
    
    
        int line[LINE_MAXLENGTH + 1];
        while (fgets(line, LINE_MAXLENGTH + 1, cmd))
        {
            float result;
            line[strcspn(line, "\n")] = '\0';
            if (strcmp(line, "DA") == 0)
            {
    
    
            }
            else if (strcmp(line, "Q") == 0)
            {
    
    
    
    
            }
            else if (strcmp(line, "H") == 0)
            {
                printf("Help Bar +, -, *, /, H, Q\n");
                continue;
            }
    
    
            else if (sscanf(line, "%c %f %f", &operations, &a, &b) == 3)
            {
                switch (operations)
                {
                case '+':
                    result = a + b;
                    break;
                case '-':
                    result = a - b;
                    break;
                case '*':
                    result = a * b;
                    break;
                case '/':
                    result = a / b;
                    break;
                default:
                    continue;
                }
            printf("%c Operator: %.1f %c %.1f = %.1f \n", operations, a, operations, b, result);
        }
    }
        return EXIT_SUCCESS;
    }

Popular pages Recent additions subscribe to a feed

Tags for this Thread