How to fix "assigned a value that is never used " error?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dkyadav80
    New Member
    • Jul 2008
    • 21

    How to fix "assigned a value that is never used " error?

    " "a" is assigned a value that is never used " getting error in C programming.

    pls any one solve this question. when and why becomes this type problem in turbo C/C++ compiler
    char a;
    FILE *f1;
    while((a=getc(f 1))!='\n')//
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    you define a
    Code:
    char a;
    but don't give it a value - so when it is used in the expresion
    Code:
    while((a=getc(f1))!='\n')//
    you get a result which depends upon the value that happened to be in the memory assigned to a

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      The error is indicating that while you are assigning a value to a in your while loop a is then never used so the assignment serves no purpose.

      Effectively you code

      Code:
      char a;
      FILE *f1;
      while((a=getc(f1))!='\n')//
      could, without effecting the operation of the rest of your program, be replaced with
      Code:
      FILE *f1;
      while(getc(f1)!='\n')//

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        You called this an error; but "assigned a value that is not used" is more typically a warning. A warning is a message from the compiler that your program is not doing anything illegal, but it is doing something odd.

        Comment

        Working...