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

  • Home
  • SEARCH
  • 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 5959211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:39:11+00:00 2026-05-22T18:39:11+00:00

I am on a low level embedded system comparing a fixed size buffer of

  • 0

I am on a low level embedded system comparing a fixed size buffer of chars to a simple string. The buffer is much larger than the string so I think that that is why the comparison operators says that the two are not equal. This prompted me to write a simple function to compare the string to the beginning of the buffer – is this an elegant solution? Thanks

int CompareString(const char* string, int strlen)
{
     //first check to see if the length is the same
     //if there is a null char at string length then
     //they are equal
     if(MsgBuffer[strlen] != '\0')
     {
         return 0; //they are not equal
     }

     strlen = strlen - 1;

     while(strlen > -1)
     {
         if(string[strlen] != MsgBuffer[strlen])
         {
              return 0; //they are equal
         }

         strlen = strlen - 1;
     }

     return 1; //they are equal
}
  • 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-22T18:39:11+00:00Added an answer on May 22, 2026 at 6:39 pm

    Here is some code you can use. Simply pass the comparison string and the buffer as two parameters. This code should also be fully compliant with MISRA-C:2004.

    sint8 gpfunc_strcmp (const uint8* s1, const uint8* s2)
    {
    
      while ((*s1 != '\0') && (*s2 != '\0'))
      {
        if (*s1 != *s2)
        {
          break;
        }
        else
        {
          s1++; 
          s2++;
        }
      }
    
      return (sint8)(*s1 - *s2);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've used strpbrk() occasionally while doing low-level string work in C, but I've never
We use a simple object model for our low level networking code at work
As a kind of opposite to this question: Is low-level embedded systems programming hard
Is there any low-level, implementation-related difference (performance-ish) between these approaches..? # check if string
This is a somewhat low-level question. In x86 assembly there are two SSE instructions:
I'm creating a low level keyboard hook in c# using SetWindowsHookEx, question is how
How do you do low low level sockets in C, example: actually sending a
Does anyone know how to access ALSA (low-level audio API) in Linux using Mono?
I have just been getting into low level programming (reading/writing to memory that sort
I recently started diving into low level OS programming. I am (very slowly) currently

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.