The meaning of these warnings. C language

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mrgenousprogram
    New Member
    • Sep 2020
    • 5

    The meaning of these warnings. C language

    Hi,

    I just started studying C programming and I began to make a console program project. I am using code block for my compiler. Looks like every time I use if statement, this warning always come

    |warning: assignment to 'int' from 'char *' makes integer from pointer without a cast [-Wint-conversion]

    warning: suggest parentheses around assignment used as truth value [-Wparentheses]|

    All I want to know is what are these warnings meaning.
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    The warnings exactly mean what the text says. Show your code.

    Comment

    • mrgenousprogram
      New Member
      • Sep 2020
      • 5

      #3
      So, is there anything I can do to fix this or I don't need to do anything?

      Comment

      • dev7060
        Recognized Expert Contributor
        • Mar 2017
        • 656

        #4
        Potential issues are indicated by warnings. Warnings would not prevent the code from being compiled. To produce a robust thing, warnings should never be ignored.
        So, is there anything I can do to fix this or I don't need to do anything?
        I can't suggest the fix if I don't know in the first place what is there to apply the fix to.

        Comment

        • mrgenousprogram
          New Member
          • Sep 2020
          • 5

          #5
          These are the codes that got warned

          Code:
          if (menu_pitagoras = "1")
          Code:
          if (menu = "1")
          all the codes that are contained within the if statement got neither warnings nor errors

          these are the codes inside the if statement

          Code:
          if (menu = "1")
              {
                  printf ("\n1. Alas\n2. Tinggi\n3. Diagonal\nPilih sisi:");
                  scanf ("%d", &menu_pitagoras);
          
                  if (menu_pitagoras = "1")
                  {
                      printf ("\nTinggi:");
                      scanf ("%f", &tinggi);
                      printf ("\nDiagonal:");
                      scanf ("%f", &diagonal);
          
                      pitagoras_alas = sqrt (tinggi*tinggi+diagonal*diagonal);
          
                      printf ("\nHasil:%f", pitagoras_alas);
                      }
          just in case if these codes needed to be checked

          Comment

          • dev7060
            Recognized Expert Contributor
            • Mar 2017
            • 656

            #6
            Use strcmp() for strings (represented as char arrays in C) and use comparison operator instead of assignment one for integer values.

            Comment

            • mrgenousprogram
              New Member
              • Sep 2020
              • 5

              #7
              Ummm, can you please give an example?

              Comment

              • dev7060
                Recognized Expert Contributor
                • Mar 2017
                • 656

                #8
                If the vars are declared as int,
                Code:
                if (menu == 1)
                Code:
                if (menu_pitagoras == 1)
                For string comparison,
                Code:
                if(strcmp(menu, "1")==0)

                Comment

                • mrgenousprogram
                  New Member
                  • Sep 2020
                  • 5

                  #9
                  Excellent, you're my project savior. I can finally continue my project

                  Comment

                  Working...