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 9242947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:41:51+00:00 2026-06-18T08:41:51+00:00

For example this is the way I have implemented it now: #include <stdio.h> #include

  • 0

For example this is the way I have implemented it now:

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

size_t *find_matches(char *needle, size_t needleSize, char *haystack, size_t haystackSize, size_t *size) {
    size_t max_matches = 256;
    size_t *matches = malloc(sizeof(size_t) * max_matches);
    int matchCount = 0;
    for(int i = 0; i + needleSize <= haystackSize; i++) {
        bool matched = true;
        for(int j = 0; j < needleSize; j++) {
            if(haystack[i + j] != needle[j]) {
                matched = false;
                break;
            }
        }

        if(matched) {
            matches[matchCount] = i;
            matchCount++;
            if(matchCount == max_matches) {
                break;
            }
        }
    }
    *size = matchCount;
    return matches;
}

int main() {
    char needle[] = {0xed, 0x57, 0x35, 0xe7, 0x00};
    char haystack[] = {0xed, 0x57, 0x35, 0xe7, 0x00, ..., 0xed, 0x57, 0x35, 0xe7, 0x00, ...};
    size_t size;
    size_t *matches = find_matches(needle, sizeof(needle), haystack, sizeof(haystack), &size);

    for(size_t i = 0; i < size; i++) {
        printf("Match %zi: %zi\n", i, matches[i]);
    }

    return 0;
}

Can this not be optimized more?

  • 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-06-18T08:41:52+00:00Added an answer on June 18, 2026 at 8:41 am

    See Rabin–Karp algorithm and others (Knuth–Morris–Pratt algorithm, Boyer–Moore algorithm).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example, your application is using this way for passing vars into your application
I'm scraping this page: http://kat.ph/search/example/?field=seeders&sorder=desc In this way: ... curl_setopt( $curl, CURLOPT_URL, $url );
PHP lists this example as a way to retrieve database data. <?php $return =
the best way to explain is with example so: this is the model public
What is the best way to parse time from a string? Example string: this
The best way I can think of to ask this is by example... In
This is just a simple question. Either way works. I prefer my first example,
I'm unsure how to do this. One way is: import urllib.request; urllib.request.urlretrieve('www.example.com/file.tar', 'file.tar') Another
Ok.. So probably an example is a good way to explain this problem So
if i have for example class A which contains the functions: //this is in

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.