For some reason this code doesn't output anything, what did I do wrong?
#include<stdio.h>
int main()
{
char c;
scanf("%s",&c);
if(c=="ab")
{
printf("b");
}
}
For some reason this code doesn't output anything, what did I do wrong?
#include<stdio.h>
int main()
{
char c;
scanf("%s",&c);
if(c=="ab")
{
printf("b");
}
}
In C String is not of type character as you have declared (i.e., char c;
). It's a pointer to a char
. You need to check for equality as character by character or use standard library function strcmp.
#include <stdio.h>
#include <string.h>
int main(void)
{
char c[100];
scanf("%s", c);
char *s = "ab";
if (strcmp(c, s) == 0)
{
printf("They are Equal\n");
}
}