Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
M

Member_16311074

@Member_16311074
About
Posts
4
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • C program(homework)
    M Member_16311074

    the debugger let me input my search string and not letting me enter my replacement string. I made it so that 10 letters can be enter into it but it stop working when I put letters over 3. Are there any chance the program is mistaking one japanese word into 3 letters?

    C / C++ / MFC data-structures regex

  • C program(homework)
    M Member_16311074

    #include
    #include

    #define MAX_STRINGS 3
    #define MAX_LENGTH 512

    // Function to perform search and replace
    void searchAndReplace(char text[][MAX_LENGTH], int numStrings, const char* searchStr, const char* replaceStr) {
    int replaced = 0;

    for (int i = 0; i < numStrings; ++i) {
        char buffer\[MAX\_LENGTH\];
        char\* pos;
        size\_t searchLen = strlen(searchStr);
        size\_t replaceLen = strlen(replaceStr);
    
        // Copy original string to buffer
        strcpy\_s(buffer, text\[i\]);
    
        // Perform the replacement
        while ((pos = strstr(buffer, searchStr)) != NULL) {
            // Print the original string before replacement
            if (!replaced) {
                printf("%s\\n", text\[i\]);
                replaced = 1;
            }
    
            // Perform the replacement
            size\_t len = strlen(pos + searchLen);
            memmove(pos + replaceLen, pos + searchLen, len + 1);
            memcpy(pos, replaceStr, replaceLen);
        }
    
        // Print the modified string if it was replaced
        if (replaced) {
            printf("%s\\n", buffer);
            replaced = 0; // Reset for the next string
        }
    }
    

    }

    int main() {
    // Prepare the strings in full-width characters
    char strings[MAX_STRINGS][MAX_LENGTH] = {
    "18歳と81歳の違い。18歳は恋に溺れる人で、81歳はお風呂に溺れる人。18歳は道を走り、逆もまた然り。81歳の人が走っている。18歳は心がもろく、81歳は骨がもろい。私は18歳で心臓が止まらない。",
    "81歳の彼は飛行機を止められない。18歳は恋に窒息することができ、81歳は餅に窒息することができる。偏差値が気になる。私は18歳で、81歳で血圧と血糖値を気にしている。まだ何も知らない18歳、もう何も覚えていない81歳。",
    "自分を探している18歳と、みんなを探している81歳。"
    };

    // Display the original strings
    printf("Original strings:\\n");
    for (int i = 0; i < MAX\_STRINGS; ++i) {
        printf("%s\\n", strings\[i\]);
    }
    
    // Input search and replacement strings
    char searchStr\[11\], replaceStr\[11\];
    printf("Enter search string (up to 10 characters): ");
    fgets(searchStr, sizeof(searchStr), stdin);
    searchStr\[strcspn(searchStr, "\\n")\] = '\\0'; // Remove newline character
    printf("Enter replacement string (up to 10 characters): ");
    fgets(replaceStr, sizeof(replaceStr), stdin);
    replaceStr\[strcspn(replaceStr, "\\n")\] = '\\0'; // Remove newline character
    
    // Ensure searchStr and replaceStr are within the allowed length
    if (strlen(searchStr) > 10 || strlen(replaceStr) > 10) {
        fprintf(stderr, "Search and replacement strings must be up to 10 characters long.\\n");
        return 1;
    }
    
    // Process
    
    C / C++ / MFC data-structures regex

  • C program(homework)
    M Member_16311074

    thanks,I got to the point of searching input and limiting it to 10 characters but I dont know how to replace that searched words.

    C / C++ / MFC data-structures regex

  • C program(homework)
    M Member_16311074

    Prepare the following strings in advance as an array. Be sure to write everything in full-width characters.
    "The difference between being 18 and 81. 18 years old is the one who drowns in love, 81 years old is the one who drowns in the bath. 18 years old is the one who runs down the road, and vice versa.
    The person running is 81 years old. An 18-year-old has a fragile heart, and an 81-year-old has a fragile bone. I'm 18 years old and my heart can't stop pounding.
    He is 81 years old and can't stop the plane. An 18-year-old can choke on love, and an 81-year-old can choke on rice cakes. I'm concerned about the deviation value
    I am 18 years old, and I am 81 years old and concerned about my blood pressure and blood sugar levels. An 18-year-old who doesn't know anything yet, an 81-year-old who doesn't remember anything anymore.
    An 18-year-old who is looking for himself, and an 81-year-old who is looking for everyone else. ”

    • Then have the user enter a search string. Search characters can be up to 10 characters.
      ・Then, have the user enter a replacement string. Replacement characters can be up to 10 characters.
    • Perform a prefix match search on the above string and replace all hit strings.
    • After replacing, output the result to the screen. If there are no conversion candidates, "Nothing to convert" is displayed.(if the searched string is in more than 1 place on the original string, the replacement will replace all of it)

    Community Verified icon

    C / C++ / MFC data-structures regex
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups