How to Create a UPC-E Barcode in C/C++

Cloudmersive
1 min readJun 14, 2021

Do you have a product or item that needs a barcode, but the area is too small to contain the standard UPC-A format? If your answer is yes, the UPC-E barcode option may be the solution you’re looking for; with only six digits, it’s half the length of the UPC-A option. To create this condensed barcode, you can use the following API in C/C++ to generate a UPC-E barcode image.

Let’s start by installing libcurl:

libcurl/7.75.0

Now, we can call our function with the following code:

CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.cloudmersive.com/barcode/generate/upc-e");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded");
headers = curl_slist_append(headers, "Apikey: YOUR-API-KEY-HERE");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
const char *data = "0=%3C&1=s&2=t&3=r&4=i&5=n&6=g&7=%3E";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);

At the end of this quick process, your new barcode will be ready as a downloadable PNG file!

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.