#include #include #include #include #include using namespace std; void getTableDimensions(int& rows, int& cols) { cout << "Enter the number of columns: "; cin >> cols; cout << "Enter the number of rows: "; cin >> rows; } vector> getTableData(int rows, int cols) { vector> table(rows, vector(cols)); cout << "Enter the table data (headers in the first row):\n"; for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { cout << "Enter data for cell [" << i + 1 << "][" << j + 1 << "]: "; cin >> ws; getline(cin, table[i][j]); } } return table; } string generateHTMLContent(const vector>& table, int rows, int cols) { string htmlContent = R"(

HTML Table

)"; for (int i = 0; i < rows; i++) { htmlContent += " \n"; for (int j = 0; j < cols; j++) { if (i == 0) htmlContent += " \n"; else htmlContent += " \n"; } htmlContent += " \n"; } htmlContent += R"(
" + table[i][j] + "" + table[i][j] + "
)"; return htmlContent; } string getDesktopPath() { char* userProfile = nullptr; size_t len; _dupenv_s(&userProfile, &len, "USERPROFILE"); if (userProfile == nullptr) { cerr << "Unable to get user profile path.\n"; exit(1); } string desktopPath = string(userProfile) + "\\Desktop\\HTML_Table"; free(userProfile); string command = "mkdir \"" + desktopPath + "\" >nul 2>&1"; system(command.c_str()); return desktopPath + "\\table.html"; } void saveHTMLToFile(const string& htmlContent, const string& filePath) { ofstream htmlFile(filePath); if (htmlFile.is_open()) { htmlFile << htmlContent; htmlFile.close(); cout << "HTML file created successfully at: " << filePath << endl; } else { cerr << "Unable to create HTML file." << endl; } } int main() { int rows, cols; getTableDimensions(rows, cols); vector> table = getTableData(rows, cols); string htmlContent = generateHTMLContent(table, rows, cols); string filePath = getDesktopPath(); saveHTMLToFile(htmlContent, filePath); return 0; }