remove a pattern "ffffff" from string "f a1 2 5 ffffffde 23 fffffff1 4 b0" using c code

alaa sam commented: show us your code first +0

Recommended Answers

All 2 Replies

#include <stdio.h>

int main(void)
{
    const char* string_before = "f a1 2 5 ffffffde 23 fffffff1 4 b0";
    const char* string_after  = "f a1 2 5 de 23 f1 4 b0";

    printf("The C-code resulted in: \"%s\".\n", string_after);

    return 0;
}

Or meh, question is poor and no effort is shown, but can't say I care for a task this small. Empower me with your downvotes, mortals! :<

#include <stdio.h>

int main(void)
{
    char string[]        = "f a1 2 5 ffffffde 23 fffffff1 4 b0";
    const char* remove   = "ffffff";
    const int remove_len = strlen(remove);
    char* offset         = NULL;

    while (offset = strstr(string, remove)) {
        strcpy(offset, offset + remove_len);
    }
    printf("Result: \"%s\".\n", string);

    return 0;
}
commented: No mortals here! :-) +12
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.