How to Adjust Unknowns in Equations Using Substitution in C?

I’m working on a C program that handles equations and I need help implementing a function to adjust unknowns within a set of equations. The code I’m currently using seems to work for a single unknown, but I’m struggling to adapt it to handle multiple unknowns.
The adjustUnknowns function takes an array of EquationResult structures, each containing an equation represented as a string. The goal is to replace the unknowns in these equations with their corresponding values, as exemplified below:
For the identified equation e = 1, we replace all instances of e with the value 1 in the other equations, excluding the identified equation itself.
I would like to expand this functionality to handle multiple unknowns. For example, in the equation 1 + 2f = 4, the unknown f should be replaced by 3/2 (result of (4 - 1) / 2).

Here is the code I am currently using:

#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define MAX_EQUATION_SIZE 256

typedef struct {
    char equation[MAX_EQUATION_SIZE];
} EquationResult;

// Function to adjust unknowns (variables) in equations
void adjustUnknowns(EquationResult results[], int numResults, EquationResult identifiedEquation) {
    // Extract the unknown and value from the identified equation
    char identifiedUnknown;
    int identifiedValue;
    sscanf(identifiedEquation.equation, "%*[^=]= %d", &identifiedValue);
    sscanf(identifiedEquation.equation, "%c", &identifiedUnknown);

    printf("Identified value: %dn", identifiedValue);
    printf("Identified unknown: %cn", identifiedUnknown);

    // Iterate through the results and adjust the unknowns
    for (int i = 0; i < numResults; i++) {
        if (strcmp(results[i].equation, identifiedEquation.equation) == 0) {
            continue; // Skip the identified equation
        }

        // Replace all instances of the unknown in the results
        char *ptr = results[i].equation;
        while ((ptr = strchr(ptr, identifiedUnknown)) != NULL) {
            // Check if there's a number before the letter (coefficient)
            if (ptr > results[i].equation && isdigit(*(ptr - 1))) {
                // Multiply the coefficient before the letter by the identified value
                int coefficient = *(ptr - 1) - '0';
                printf("Found coefficient: %dn", coefficient);

                int newValue = coefficient * identifiedValue;
                printf("New value: %dn", newValue);

                // Convert the new value to string
                char newValueStr[MAX_EQUATION_SIZE];
                sprintf(newValueStr, "%d", newValue);

                // Calculate the length of the new value and the coefficient
                int newValueLen = strlen(newValueStr);
                int coefficientLen = ptr - 1 - results[i].equation; // Length of the coefficient

                // Replace the coefficient and the unknown with the new value
                memcpy(results[i].equation + coefficientLen, newValueStr, newValueLen);
                strcpy(results[i].equation + coefficientLen + newValueLen, ptr + 1); // Copy the rest of the string

                ptr = results[i].equation + coefficientLen + newValueLen; // Update the pointer after replacement
            } else {
                // Replace the unknown with the identified value directly
                sprintf(ptr, "%d", identifiedValue);
                ptr++; // Move the pointer forward after replacement
                // Copy the rest of the string after replacing the unknown
                strcpy(ptr, ptr + 1);
            }
        }
    }
}

int main() {
    // Example results after substitution among equations
    EquationResult results[] = {
        {"1 = a"},
        {"2d = 1"},
        {"e + 2f = 4"},
        {"e = 1"},
        {"3c + f = 4"},
        {"2c = b"}
    };

    // Example of an identified equation with a single valid unknown
    EquationResult identifiedEquation = {"e = 1"};
    
    // Call the function to adjust unknowns in the results
    adjustUnknowns(results, sizeof(results) / sizeof(results[0]), identifiedEquation);

    // Display the adjusted results
    printf("Results after adjusting unknowns:n");
    for (int i = 0; i < sizeof(results) / sizeof(results[0]); i++) {
        printf("%sn", results[i].equation);
    }

    return 0;
}

Result:

Identified value: 1
Identified unknown: e
Results after adjusting unknowns:
1 = a
2d = 1
1+ 2f = 4
e = 1
3c + f = 4
2c = b

I need help modifying the adjustUnknowns function or creating another function to handle multiple unknowns and perform the correct substitutions in the equations. How can I adapt this function to work with multiple unknowns, following the described substitution method?

Thank you in advance for any guidance or suggestions!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật