#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
// Twilio credentials
#define ACCOUNT_SID "YOUR_TWILIO_ACCOUNT_SID"
#define AUTH_TOKEN "YOUR_TWILIO_AUTH_TOKEN"
#define TWILIO_PHONE_NUMBER "+YOUR_TWILIO_PHONE_NUMBER"
// Function to calculate electricity bill based on slabs
float calculateElectricityBill(int units) {
float rate;
if (units <= 100) {
rate = 3.00;
} else if (units <= 200) {
rate = 4.50;
} else if (units <= 300) {
rate = 6.50;
} else {
rate = 8.00;
}
return units * rate;
}
// Function to calculate phone bill based on call minutes
float calculatePhoneBill(int callMinutes) {
float rate = 1.00; // ₹1 per minute
return callMinutes * rate;
}
// URL Encoding function for safe transmission
char* url_encode(const char* str) {
CURL *curl = curl_easy_init();
if (curl) {
char *output = curl_easy_escape(curl, str, 0);
curl_easy_cleanup(curl);
return output;
}
return NULL;
}
// Function to send SMS using Twilio API
void sendSMS(const char *recipientPhoneNumber, const char *customerName, float electricityBill, float phoneBill) {
CURL *curl;
CURLcode res;
// Construct the SMS message
char message[512];
snprintf
(message
, sizeof(message
), "Dear %s, your electricity bill is ₹%.2f and your phone bill is ₹%.2f. Total amount due: ₹%.2f. Thank you!",
customerName, electricityBill, phoneBill, electricityBill + phoneBill);
// URL encode the message
char *encodedMessage = url_encode(message);
// Construct the URL dynamically
char url[256];
"https://a...content-available-to-author-only...o.com/2010-04-01/Accounts/%s/Messages.json",
ACCOUNT_SID);
// Prepare POST fields
char postFields[1024];
snprintf
(postFields
, sizeof(postFields
), "To=%s&From=%s&Body=%s",
recipientPhoneNumber, TWILIO_PHONE_NUMBER, encodedMessage);
// Initialize cURL
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_USERNAME, ACCOUNT_SID);
curl_easy_setopt(curl, CURLOPT_PASSWORD, AUTH_TOKEN);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postFields);
// Disable SSL verification (TEMPORARY FIX)
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
// Perform the request, and check for errors
res = curl_easy_perform(curl);
if (res != CURLE_OK) {
fprintf(stderr
, "curl_easy_perform() failed: %s\n", curl_easy_strerror
(res
)); } else {
printf("\nSMS sent successfully to %s!\n", recipientPhoneNumber
); }
// Cleanup
curl_easy_cleanup(curl);
}
curl_global_cleanup();
if (encodedMessage) {
curl_free(encodedMessage);
}
}
int main() {
char customerName[50];
char recipientPhoneNumber[15];
int electricityUnits, phoneMinutes;
float electricityBill, phoneBill, totalBill;
// Input customer name
printf("Enter customer name: "); customerName
[strcspn(customerName
, "\n")] = '\0'; // Remove newline character
// Input customer phone number
printf("Enter recipient phone number (in E.164 format, e.g., +919876543210): "); fgets(recipientPhoneNumber
, sizeof(recipientPhoneNumber
), stdin
); recipientPhoneNumber
[strcspn(recipientPhoneNumber
, "\n")] = '\0'; // Remove newline character
// Input electricity usage
printf("Enter electricity units consumed: "); scanf("%d", &electricityUnits);
// Input phone usage
printf("Enter phone call minutes used: "); scanf("%d", &phoneMinutes);
// Calculate bills
electricityBill = calculateElectricityBill(electricityUnits);
phoneBill = calculatePhoneBill(phoneMinutes);
totalBill = electricityBill + phoneBill;
// Display bill summary
printf("\n--- Bill Summary ---\n"); printf("Customer Name: %s\n", customerName
); printf("Electricity Bill: ₹%.2f\n", electricityBill
); printf("Phone Bill: ₹%.2f\n", phoneBill
); printf("Total Bill Amount: ₹%.2f\n", totalBill
);
// Send SMS notification
sendSMS(recipientPhoneNumber, customerName, electricityBill, phoneBill);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgojaW5jbHVkZSA8Y3VybC9jdXJsLmg+CgovLyBUd2lsaW8gY3JlZGVudGlhbHMKI2RlZmluZSBBQ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GN1c3RvbWVyTmFtZSk7CiAgICBwcmludGYoIkVsZWN0cmljaXR5IEJpbGw6IOKCuSUuMmZcbiIsIGVsZWN0cmljaXR5QmlsbCk7CiAgICBwcmludGYoIlBob25lIEJpbGw6IOKCuSUuMmZcbiIsIHBob25lQmlsbCk7CiAgICBwcmludGYoIlRvdGFsIEJpbGwgQW1vdW50OiDigrklLjJmXG4iLCB0b3RhbEJpbGwpOwoKICAgIC8vIFNlbmQgU01TIG5vdGlmaWNhdGlvbgogICAgc2VuZFNNUyhyZWNpcGllbnRQaG9uZU51bWJlciwgY3VzdG9tZXJOYW1lLCBlbGVjdHJpY2l0eUJpbGwsIHBob25lQmlsbCk7CgogICAgcmV0dXJuIDA7Cn0K
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
// Twilio credentials
#define ACCOUNT_SID "YOUR_TWILIO_ACCOUNT_SID"
#define AUTH_TOKEN "YOUR_TWILIO_AUTH_TOKEN"
#define TWILIO_PHONE_NUMBER "+YOUR_TWILIO_PHONE_NUMBER"
// Function to calculate electricity bill based on slabs
float calculateElectricityBill(int units) {
float rate;
if (units <= 100) {
rate = 3.00;
} else if (units <= 200) {
rate = 4.50;
} else if (units <= 300) {
rate = 6.50;
} else {
rate = 8.00;
}
return units * rate;
}
// Function to calculate phone bill based on call minutes
float calculatePhoneBill(int callMinutes) {
float rate = 1.00; // ₹1 per minute
return callMinutes * rate;
}
// URL Encoding function for safe transmission
char* url_encode(const char* str) {
CURL *curl = curl_easy_init();
if (curl) {
char *output = curl_easy_escape(curl, str, 0);
curl_easy_cleanup(curl);
return output;
}
return NULL;
}
// Function to send SMS using Twilio API
void sendSMS(const char *recipientPhoneNumber, const char *customerName, float electricityBill, float phoneBill) {
CURL *curl;
CURLcode res;
// Construct the SMS message
char message[512];
snprintf(message, sizeof(message),
"Dear %s, your electricity bill is ₹%.2f and your phone bill is ₹%.2f. Total amount due: ₹%.2f. Thank you!",
customerName, electricityBill, phoneBill, electricityBill + phoneBill);
// URL encode the message
char *encodedMessage = url_encode(message);
// Construct the URL dynamically
char url[256];
snprintf(url, sizeof(url),
"https://a...content-available-to-author-only...o.com/2010-04-01/Accounts/%s/Messages.json",
ACCOUNT_SID);
// Prepare POST fields
char postFields[1024];
snprintf(postFields, sizeof(postFields),
"To=%s&From=%s&Body=%s",
recipientPhoneNumber, TWILIO_PHONE_NUMBER, encodedMessage);
// Initialize cURL
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_USERNAME, ACCOUNT_SID);
curl_easy_setopt(curl, CURLOPT_PASSWORD, AUTH_TOKEN);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postFields);
// Disable SSL verification (TEMPORARY FIX)
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
// Perform the request, and check for errors
res = curl_easy_perform(curl);
if (res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
} else {
printf("\nSMS sent successfully to %s!\n", recipientPhoneNumber);
}
// Cleanup
curl_easy_cleanup(curl);
}
curl_global_cleanup();
if (encodedMessage) {
curl_free(encodedMessage);
}
}
int main() {
char customerName[50];
char recipientPhoneNumber[15];
int electricityUnits, phoneMinutes;
float electricityBill, phoneBill, totalBill;
// Input customer name
printf("Enter customer name: ");
fgets(customerName, sizeof(customerName), stdin);
customerName[strcspn(customerName, "\n")] = '\0'; // Remove newline character
// Input customer phone number
printf("Enter recipient phone number (in E.164 format, e.g., +919876543210): ");
fgets(recipientPhoneNumber, sizeof(recipientPhoneNumber), stdin);
recipientPhoneNumber[strcspn(recipientPhoneNumber, "\n")] = '\0'; // Remove newline character
// Input electricity usage
printf("Enter electricity units consumed: ");
scanf("%d", &electricityUnits);
// Input phone usage
printf("Enter phone call minutes used: ");
scanf("%d", &phoneMinutes);
// Calculate bills
electricityBill = calculateElectricityBill(electricityUnits);
phoneBill = calculatePhoneBill(phoneMinutes);
totalBill = electricityBill + phoneBill;
// Display bill summary
printf("\n--- Bill Summary ---\n");
printf("Customer Name: %s\n", customerName);
printf("Electricity Bill: ₹%.2f\n", electricityBill);
printf("Phone Bill: ₹%.2f\n", phoneBill);
printf("Total Bill Amount: ₹%.2f\n", totalBill);
// Send SMS notification
sendSMS(recipientPhoneNumber, customerName, electricityBill, phoneBill);
return 0;
}