Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6360401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:38:42+00:00 2026-05-24T23:38:42+00:00

Good evening, I have 2 functions and each of them accepts as argument a

  • 0

Good evening, I have 2 functions and each of them accepts as argument a pointer to char:

char pointer[255];
func1(char* pointer)
{
...
memcpy(pointer,some_char,strlen(something));
return;
}
func2(char* pointer)
{
...
if (pointer==someother_char) exit(0); //FAILs
//also I have
if(pointer==someother_pointer2char); // FAILs
}

Now I’ve tried strstr,strcmp etc… doesn’t work. Wanted to try memcmp but I don’t have static len. As I have to compare char* to char and char* to char* I would be needing two solutions right?

So, how to compare these pointers (actually pointees) in shortest possible way?

Thanks.

E D I T

Thanks to wallacer and Code Monkey now for char* to char comparison I use following:

func1(char* ptr){
char someother_char[255];
char *ptr_char = NULL; //I have to strcmp a few values so this is why I initialize it first
... 
ptr_char = someother_char;
if (strcmp(ptr,ptr_char) == 0) //gtfo and it does...
...
ptr_char = some2nd;
if(strcmp...

Any suggestions maybe… (hmm external function for comparing?)

Suggestion1(by Code Monkey)

#include <stdio.h>

int main(void) {
    char tempchar[255];
    tempchar[0] = 'a';
    tempchar[1] = 'b';
    tempchar[2] = '\0';
    char *ptr_char;
    ptr_char = &tempchar[0];
    printf("%s", ptr_char);
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:38:42+00:00Added an answer on May 24, 2026 at 11:38 pm

    You need to use strcmp. Not seeing how you tried to use it, this is how you should use it:

    char *someother_char = "a";
    char *pointer = "a";
    
    if (strcmp(pointer, someother_char) == 0) { // match!
    }
    else { // not matched 
    }
    

    to then do the comparison with a char, you have to promote to a char*:

    char *someother_char1;
    char test = 'a';
    char *pointer = "a";
    
    strncpy((char*)test,someother_char1,sizeof(test));
    
    if (strcmp(pointer, someother_char1) == 0) { // match!
    }
    else { // not matched 
    }
    

    if you want to use the char array then you have to de-reference:

    char char_array[255];
    // don't forget to fill your array
    // and add a null-terminating char somewhere, such as char_array[255] = '\0';
    char *ptr_somechar = &char_array[0];
    char *pointer = "a";
    
    if (strcmp(pointer, ptr_somechar) == 0) { // match!
    } else { // not matched
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

good evening, i have these five functions that i use to reduce server load
Good evening, I would like to have a navigation bar which is centralised to
Good evening, I have been trying to wrap my head about this, below, code
Good evening ladies and gentlemen, I have a problem with Java Swing that I
Good evening, In my app that I'm currently developing, I have a class that
Good evening I have a JTable that I built with a TableModel how to
Good evening, I have used BeautifulSoup to extract some data from a website as
Good Evening, i have a problem in running a progress bar, please check my
Good evening! I'm pretty new to Linux and Apache and I have a problem
Good evening, I have one table, with a timestamp column, then I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.