Sign in to follow this  

Error trying two compare to values. (C/C++)

This topic is 3627 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to look at a char array and see if an individual char is equal to 1. Heres my code.
#include <stdio.h>
#include <stdlib.h>
#include <string>

/*****************************************************/
int bit_to_ascii(const char core[ ], char data[ ]) {
/*****************************************************/

int i = 0; /* var for loop */

int len = strlen(core); /* calc lenth of core */

for (i; i < len ; i++){

  if (core [i] == "1"){

    printf ("%c", core [i]);

  }
}

system ("pause");


}/*****************************************************/

int main()
{
  int x;
  const char stuff[48] = "r5 0 #! 1 1 gP 0 f66-:] 0 [ } 1 v4t^ 0 1 n>?:77";
  char things[2] = " ";

  bit_to_ascii(stuff,things);

  return 0;
}

I get the error ANSI C++ forbids comparison between pointer and integer. So then I change
if (core [i] == "1"){

to
if (core [i] == 1){

and it compiles error free, but when I execute it, none of the 1's show up. Where am I going wrong. Also try to leave thing specific to C++ out as it's kind of a long story.

Share this post


Link to post
Share on other sites

This topic is 3627 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this