Professional Documents
Culture Documents
Escape Sequence-Connecting with Devices
Escape Sequence-Connecting with Devices
#include <stdio.h>
int main() {
printf("I am IITJ Student\a\n");
return 0;
}
Write a C program to print: I am Ω”
Write a C program to print: I am Ω”
#include <stdio.h>
int main(){
printf("I am \u03A9");
return 0;
}
Write a C program to print: "I ♥ Dogs”
Write a C program to print: "I ♥ Dogs”
#include <stdio.h>
int main() {
return 0;
}
C program to change the text color
#include <stdio.h>
int main() {
// ANSI escape codes to set text color
printf("\033[1;31m"); // Set text to bright red
printf("This text is red!\n");
return 0;
}
What is this?
#include <stdio.h>
\033 -> escape sequence for color
int main() {
// ANSI escape codes to set text color
printf("\033[1;31m"); // Set text to red
printf("This text is red!\n");
return 0;
}
Many more escape sequences - study on your
own
Simple system level program
• Creating a system-level program in C can involve various tasks such as
le manipulation, process control, or interacting with the operating
system's system calls.
int main() {
printf("Running the 'ls' command to list directory contents:\n");
if (status == -1) {
• system() // If system() fails
printf("Failed to execute command\n");
} else {
// Output the return status of the 'ls' command
printf("\nCommand executed successfully with return status %d\n", WEXITSTATUS(status));
}
return 0;
}
fi
Get the CUPS library
•
#include <cups/cups.h>
#include <stdio.h>
int main() {
// Name of the le to print
const char * lename = "sample.txt";
// Name of the printer (NULL for the default printer)
const char *printer = NULL;
// Check if CUPS server is running and get the default printer if none speci ed
if ((printer = cupsGetDefault()) == NULL) {
fprintf(stderr, "Error: No default printer available\n");
return 1;
}
if (job_id == 0) {
fprintf(stderr, "Failed to print le: %s\n", cupsLastErrorString());
return 1;
}
• Install OpenCV
// Read and display frames from the camera until a key is pressed
while (1) {
// Capture frame-by-frame
IplImage* frame = cvQueryFrame(capture);
#include <opencv2/opencv.h>
#include <stdio.h> // If the frame is empty, break immediately
if (!frame)
int main() { break;
// Create a VideoCapture object and open the input le
// Change '0' to '1' or '2' // Display the resulting frame
//if you have multiple cameras to select which one to use cvShowImage("Camera Output", frame);
CvCapture* capture = cvCaptureFromCAM(0);
// Press 27 (ESC) to exit
// Check if camera opened successfully char c = (char)cvWaitKey(25);
if (!capture) { if (c == 27)
fprintf(stderr, "Error: Unable to open camera\n"); break;
return -1; }
}
// When everything done, release the video capture and write object
cvReleaseCapture(&capture);
cvDestroyWindow("Camera Output");
return 0;
}
fi
Object Oriented Programming
• Encapsulation: This involves bundling the data (attributes) and the methods (functions or operations)
that operate on the data into a single unit or class. This encapsulation provides a protective barrier that
prevents the code from being accessed directly by other parts of the program, except through the
methods de ned in the class.
• Inheritance: This allows a class to inherit attributes and methods from another class, referred to as its
parent class. This feature helps in reducing redundancy and increases reusability. For example, a 'Dog'
class could inherit from a more general 'Animal' class.
• Polymorphism: This allows methods to do di erent things based on the object it is acting upon. This
means a single function can work in di erent ways on di erent objects.
• Abstraction: This principle involves hiding complex realities while exposing only the necessary parts of
objects and features to the outside world. It helps in handling complexity by hiding unnecessary details
and showing only essential attributes of an object
fi
ff
ff
ff
Object Oriented Programming
• OOP in C is non-trivial
• Make sure that Python is installed on your system. You can download and
install Python from python.org