-1

idk why it always come out [Warning] comparison between pointer and integer in line 18 and 26. what should I change the error i get is

[Warning] comparison between pointer and integer

Im new to coding so i need some help

The problem should be in this line

#include <stdio.h>
#include <string.h>

char type_of_paper[20];
float marks_1, marks_2, Total_1_Mark, pp2_marks;


void main()
{
    
    
    printf("\nEnter type of paper [1/2] :");
    gets(type_of_paper);
    
    if(type_of_paper == '1' )
    {
        printf("\nEnter Section A and Section B marks: ");
        scanf("%f %f", &mark_1, &marks_2);
        Total_1_Mark = marks_1 + marks_2;
        printf("\nPaper Type : Paper 1");
        printf("\nTotal paper 1 Mark : %2f", Total_1_Mark);
    }
    else if(type_of_paper == '2')
    {
        printf("\nEnter paper2 marks :");
        scanf("%f", &pp2_marks);
        printf("\nPaper Type : Paper 2");
        if(pp2_marks < 60)
        {
            printf("Status : noob");
        }
        else if (pp2_marks < 80)
        {
            printf("Status : Good");
        }
        else if (pp2_marks <= 100)
        {
            printf("Status : Excellent");
        }
        else printf("whats wrong with u");
    }
    else printf("type again");
    
    
}  
  • 6
    Please provide a working example. What is the type of `type_of_assessment`? – 12431234123412341234123 Sep 01 '21 at 10:42
  • 1
    Not relevant to your question, but ALWAYS check the return value of `scanf()` and only proceed with using variables after some value was written to them. – 12431234123412341234123 Sep 01 '21 at 10:43
  • 1
    Please [edit] your question to include a proper [mre]. – Some programmer dude Sep 01 '21 at 10:43
  • 3
    If `type_of_assessment` is a `char *`, that would explain it. – bereal Sep 01 '21 at 10:44
  • 2
    I'm guessing that `type_of_assignment` is either a `char *` or an array of `char`? In that case, you probably need `if (strcmp(type_of_assignment, "Q") == 0)`, or if the `type_of_assignment` string is always a single character string (plus a null terminator), you could use `if (type_of_assignment[0] == 'Q')` instead. – Ian Abbott Sep 01 '21 at 10:45
  • In addition to what @IanAbbott says about possible solutions, why not define `type_of_assignment` as a plain `char`? – Some programmer dude Sep 01 '21 at 10:47
  • Does this answer your question? [Warning comparison between pointer and integer](https://stackoverflow.com/questions/32510218/warning-comparison-between-pointer-and-integer) – user438383 Sep 01 '21 at 11:05
  • Besides what's already been said, ***never ever*** use the `gets`! [It's so dangerous](https://stackoverflow.com/questions/1694036/why-is-the-gets-function-so-dangerous-that-it-should-not-be-used) that was removed from the C standard in 2011 (and was deprecated long before that). Use e.g. [`fgets`](https://en.cppreference.com/w/c/io/fgets) to read strings instead. – Some programmer dude Sep 01 '21 at 11:15

2 Answers2

2

I'm assuming that this "type_of_assessment" variable is of char * (pointer to a character) so when you are comparing a character to a char pointer it throws this error. This char * variable stores the address of the actual value stored so you have to de reference it first. Try this in your if condition:

if (*type_of_assessment == 'Q') {...}
chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256
0

You are trying to compare(==) the address of variable and char/ string. Firstly get the value using pointer through reference then compare it

Solution:-

if (*type_of_assessment == 'Q'){your further code}