Thread: Im getting one error and six warnings i think im overlooking something

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

    Im getting one error and six warnings i think im overlooking something

    Code:
    #include <stdio.h>
    #include <ctype.h>
    #include <string.h>
    #include <stdlib.h>
    #include <math.h>
    #define LINE_MAXLENGTH 80
    
    
    
    
    int main()
    {
        float a, b;
        char operations;
    
    
    
    
        FILE* cmd = fopen("CommandsProj2.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 else(strcmp(line, "DA") == 0)
    
    
              else  (cmd == '*')
                {
                    sscanf("%d %d",&a,&b);
                    multiply(a,b,ofp);
                }
                else (cmd == '-')
                {
                    sscanf("%d %d",&a,&b);
                    substract(a,b,ofp);
                }
                else (cmd == '/')
                {
                    sscanf("%d %d",&a,&b);
                    divide(a,b,ofp);
                }
                else (cmd == 'C')
                {
                    sscanf("%c",&ch);
                    toUpperCase(ch,ofp);
                }
                else (cmd == 'c')
                {
                    sscanf("%c",&ch);
                    toLowerCase(ch,ofp);
                }
                else (cmd == 'P')
                {
                    sscanf("%d %d",&a, &b);
                    printKthDigit(a,b,ofp);
                }
                else (cmd == 'R')
                {
                    sscanf("%lf %d",&firstDouble,&b);
                    roundDecimal(firstDouble, b,ofp);
                }
                else (cmd == 'S')
                {
                    sscanf("%lf",&firstDouble);
                    separte(firstDouble,ofp);
                }
                else (cmd == 'D')
                {
                    sscanf("%d %d",&a,&b);
                    partitionInteger(a,b,ofp);
                }
                else (cmd == 'H')
                {
                    help(ofp);
                }
                else (cmd == 'Q')
                {
                    break;
                }
                else
                {
            printf("%c Operator: %.1f %c %.1f = %.1f \n", operations, a, operations, b, result);
        }
    }
        return EXIT_SUCCESS;
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You should state the error and warning messages.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2014
    Location
    Miami, Florida, United States
    Posts
    19
    Quote Originally Posted by laserlight View Post
    You should state the error and warning messages.
    ohh no problem

    |28|warning: passing argument 1 of 'fgets' from incompatible pointer type [enabled by default]|
    |31|warning: passing argument 1 of 'strcspn' from incompatible pointer type [enabled by default]|
    |32|error: expected '(' before 'else'|
    |30|warning: unused variable 'result' [-Wunused-variable]|
    |12|warning: unused variable 'operations' [-Wunused-variable]|
    |11|warning: unused variable 'b' [-Wunused-variable]|
    |11|warning: unused variable 'a' [-Wunused-variable]|

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    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.

  5. #5
    Registered User
    Join Date
    Dec 2014
    Location
    Miami, Florida, United States
    Posts
    19
    Which is my account also

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by RudoDouglas View Post
    Which is my account also
    Cross-posting is against the rules, probably on both forums. It wastes everyone's time and effort, unless you do a very good job of duplicating the updates on both threads to keep them in sync.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  7. #7
    Registered User
    Join Date
    Dec 2014
    Location
    Miami, Florida, United States
    Posts
    19
    Quote Originally Posted by Elkvis View Post
    Cross-posting is against the rules, probably on both forums. It wastes everyone's time and effort, unless you do a very good job of duplicating the updates on both threads to keep them in sync.
    Just tell me what's wrong with it if I need to start the whole program over then tell me telling me all this is wasting everyone's time

  8. #8
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by RudoDouglas View Post
    telling me all this is wasting everyone's time
    Call it an investment of "preventive maintenance." If we take the time to educate you on proper forum etiquette now, maybe next time, you'll follow the rules and get better results.

    In any case, your problem stems from the fact that you're declaring line as an array of int, rather than an array of char. fgets() and strcspn() both require a char* as their first argument, so an array of int (which decays to int*) will not work.

    Edit:
    After looking further, I can see that there are so many problems with your code that make it very clear that you don't understand what you're doing at all. It appears that you need to buy a C book, and start at the very beginning. It's clear that this program is well above your ability level at this time.
    Last edited by Elkvis; 12-10-2014 at 02:27 PM.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  9. #9
    Registered User
    Join Date
    Dec 2014
    Location
    Miami, Florida, United States
    Posts
    19
    Quote Originally Posted by Elkvis View Post
    Call it an investment of "preventive maintenance." If we take the time to educate you on proper forum etiquette now, maybe next time, you'll follow the rules and get better results.

    In any case, your problem stems from the fact that you're declaring line as an array of int, rather than an array of char. fgets() and strcspn() both require a char* as their first argument, so an array of int (which decays to int*) will not work.

    Edit:
    After looking further, I can see that there are so many problems with your code that make it very clear that you don't understand what you're doing at all. It appears that you need to buy a C book, and start at the very beginning. It's clear that this program is well above your ability level at this time.
    Lol yes it very much is don't worry after this is done I wouldn't need this anymore I'm clearly not gonna be a programmer not my cup of tea at all. But I know how to open and read a file and print it and also print the answers in a loop but adding the round, separate, partition, and upper lower case is even more beyond me.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 02-01-2014, 11:49 PM
  2. warnings & error messages
    By cfanatic in forum C Programming
    Replies: 39
    Last Post: 08-03-2012, 08:39 PM
  3. Overlooking something in a comparison
    By csharp100 in forum C Programming
    Replies: 7
    Last Post: 04-29-2012, 09:21 PM
  4. probably something simple I'm overlooking
    By tomasc in forum C++ Programming
    Replies: 3
    Last Post: 05-19-2008, 11:07 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

Tags for this Thread