-4
int main(void)
{
    char co;

        printf("Enter item code: ");
        scanf("%s", co);

    if(co == "ST200")
    {
         a1 += price * no * 0.90;
    }

}

warning: comparison between pointer and integer if(co == "ST200" && card == 'Y')

i am recieving a message like this after compling.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Praveenkumar
  • 9
  • 1
  • 4
  • To compare two strings in C you need to use [`strcmp`](http://en.cppreference.com/w/c/string/byte/strcmp). Any [good beginners book](http://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list) would have told you that. – Some programmer dude May 30 '17 at 02:32
  • And it's even worse, since you try to read a string using only a single uninitialized character. A string in C is an *array* of characters, terminated by a zero. *Also* something [a good beginners book](http://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list) would have told you. So please stop at once, and go find a book, and read it. – Some programmer dude May 30 '17 at 02:33

2 Answers2

3

You made co a character, but %s is for strings.

Also:

if(co == "ST200")

Since "ST200" is a pointer to a constant and co does not point to a constant, these two can never be equal. So what's the point of this comparison?

Bluntly, you need to learn how to handle strings in C before you attempt to write code that uses them.

David Schwartz
  • 179,497
  • 17
  • 214
  • 278
1

The Correct way to write this program would be.

#include <stdio.h>
#include <string.h>
int main(void)
{
    char co[10];
    printf("Enter item code: ");
    scanf("%s", co);

if(!strcmp("ST200",co))
{
     a1 += price * no * 0.90;
}
}

co need to be an array to store string. For comparison you need to use strcmp(const char *Str1,const char *Str2) which will result zero when two strings are matched. So use a not operator before. Also refer any fundamental C book. Hope this helps :)

Vishwajeet Vishu
  • 492
  • 3
  • 16