1

My understanding is, if we run the function for the binary form of that string, it could be faster. For example, let, a string "AAABVAVBBA" is written in a text file test.txt in the hard drive.

Now I want to run KMP string matching algorithm in C and use the binary string of string "AAABVAVBBA" as input (pattern is already given in binary array).

When we save test.txt in the hard drive, it is already in the binary form, so how can I access that binary form of "AAABVAVBBA" in the memory (hard drive) using C?

Note I am not asking how to convert "AAABVAVBBA" string to a binary string (like this post). I want to get the binary form already saved in the hard drive (memory), which is used by assembler.

My query is close to this post.

0

2 Answers 2

2

I don't know if this will answer your question, but please run and study this program:

#include <stdio.h>

int main()
{
    FILE *fp = fopen("test.text", "r");
    if(fp == NULL) return 1;

    char buf[100];
    int r = fread(buf, 1, sizeof(buf), fp);
    if(r <= 0) return 1;

    printf("as string: %.*s", r, buf);

    int i;
    printf("as characters:");
    for(i = 0; i < r; i++) printf(" %c", buf[i]);
    printf("\n");

    printf("as integers:");
    for(i = 0; i < r; i++) printf(" %d", buf[i]);
    printf("\n");

    return 0;
}
Sign up to request clarification or add additional context in comments.

1 Comment

0

Here is a bit modified version of @steves program.

https://godbolt.org/z/9dEK6f11h

It writes (and reads of course) in binary and in text mode. Spot the difference if you can. I can't. So you try to solve non-existing problem.

All credit to Steve Summit (upvote his answer)

2 Comments

You are seeing assembly language, assembler will use this instructions with binary data, if there is a way to see that, you will see, not in the assembly language.
You are looking into wrong window

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.