C, Linux

Create QR codes with c


To create QR codes we are going to use open source library libqrencode.


I you are in Ubuntu install libqrencode by issuing the following command:

sudo apt-get install libqrencode libqrencode-dev

Source code

#include <stdio.h>
#include <qrencode.h>
#include <errno.h>
int main(){
    QRcode *qrcode;
    qrcode = QRcode_encodeString("http://webnetsoft.gr", 4, QR_ECLEVEL_H, QR_MODE_8, 0);
    if(qrcode == NULL) {
	printf("An error has occured (%d).n", errno);
	if(errno == EINVAL){
		printf("Invalid input objectn");
	else if(errno == ENOMEM) {
		printf("Unable to allocate memory for input objects.n");
	else if(errno == ERANGE) {
		printf("Input data is too large.n");
	return 1;
    printf("%s", qrcode->data);
    return 0;


gcc -o encode encode.c -lqrencode