Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

431
Visualizações
How to compare pointer and integer?

I'm trying to check if pointer is pointing at some char.

Like this:

#include<stdio.h>
#include<string.h>
#define a 3
int func(char *);
int main()
{
char *s="a";
int type;
type=func(s);
printf("%d",type);

    return 0;
}
int func(char *s)
{
int type;
if(*s=="a") 
{
type=1;
}
return type;

}

But I constantly get warning: warning: comparison between pointer and integer if(*s=="a")

Is it possible to compare pointer and integers?

Is there another way to resolve this problem?

Can I find out at which letter is pointing *s without printing it?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

"a" is not a character, it is a string literal. 'a' is a character literal, which is what you are looking for here.

Also note that in your comparison *s == "a" it is actually the "a" which is the pointer, and *s which is the integer... The * dereferences s, which results in the char (an integer) stored at the address pointed to by s. The string literal, however, acts as a pointer to the first character of the string "a".

Furthermore, if you fix the comparison by changing it to *s == 'a', you are only checking whether the first character of s is 'a'. If you wish to compare strings, see strcmp.

over 4 years ago · Santiago Trujillo Relatório

0

chars are enclosed in '' not ""

#include<stdio.h>
#include<string.h>
#define a 3
int func(char *);
int main()
{
char value = 'a';
char *s=&value;
int type;
type=func(s);
printf("%d",type);

    return 0;
}
int func(char *s)
{
int type;
if(*s=='a') //or if(*s==3)
{
type=1;
}
return type;

}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda