Print Hard Copy Using Tkinter

Dev Prakash Sharma
Updated on 06-Mar-2021 08:15:50

938 Views

Tkinter allows developers to interact with the files inside the local system. In this article, we will see how to print a hardcopy of a file using Tkinter packages such as filedialog and win32api module.In order to import these packages, we have to first install these modules in our environment. To install win32api, we will use pip install pywin32Example#import the required libraries from tkinter import * from tkinter import filedialog import win32api #Create an instance of tkinter frame or window win= Tk() win.title('Print Hard Copy') win.geometry("700x400") #Define function def print_file():    file= filedialog.askopenfilename(initialdir="/", title="Select any file", filetypes=(("Text ... Read More

C Program to Demonstrate Post-Increment and Pre-Increment Operators

Bhanu Priya
Updated on 06-Mar-2021 08:02:49

3K+ Views

Increment operator (++)It is used to increment the value of a variable by 1. There are two types of increment operators, pre-increment and post-increment.The increment operator is placed before the operand in pre-increment and the value is first incremented and then the operation is performed on it.For example, z = ++a; a= a+1 z=aThe increment operator is placed after the operand in post-increment and the value is incremented after the operation is performed.For example, z = a++; z=a a= a+1Example 1Following is an example for pre-increment operator − Live Demomain ( ){    int A= 10, Z;    Z= ++A;   ... Read More

Write C Program Using isupper Function

Bhanu Priya
Updated on 06-Mar-2021 07:59:15

235 Views

ProblemHow to identify a total number of upper-case alphabets in a string using C Programming?SolutionThe logic we used to count number of upper-case letters in a sentence is as follows −for(a=string[0];a!='\0';i++){    a=string[i];    if (isupper(a)){       counter=counter+1;       //counter++;    } }Example 1 Live Demo#include #include void main(){    //Declaring integer for number determination, string//    int i=0;    char a;    char string[50];    int counter=0;    //Reading User I/p//    printf("Enter the string :");    gets(string);    //Using For loop and predefined function to count upper case alpha's//    for(a=string[0];a!='\0';i++){       a=string[i]; ... Read More

Explain malloc Function in C Programming

Bhanu Priya
Updated on 06-Mar-2021 07:56:53

732 Views

ProblemWrite a C program to display and add the elements using dynamic memory allocation functions.SolutionIn C, the library function malloc allocates a block of memory in bytes at runtime. It returns a void pointer, which points to the base address of allocated memory and it leaves the memory uninitialized.Syntaxvoid *malloc (size in bytes)For example, int *ptr;ptr = (int * ) malloc (1000);int *ptr;ptr = (int * ) malloc (n * sizeof (int));Note − It returns NULL, if the memory is not free.Example Live Demo#include #include void main(){    //Declaring variables and pointers, sum//    int numofe, i, sum=0;    int *p; ... Read More

Check atexit Function in C

Bhanu Priya
Updated on 06-Mar-2021 07:52:09

581 Views

The atexit() is a function that allows the user to register a function that has to be called based on program termination.It is a predefined function that is included in stdlib header files.Example 1 Live Demo#include #include void welcome(void){    printf("Welcome to New, "); } void world(void){    printf("World"); } int main(){    //test atexit ,call user defined function    atexit(world);    atexit(welcome);    return 0; }OutputWelcome to New, WorldExample 2 Live Demo#include #include void first(void){    printf("This is a beautiful, "); } void second(void){    printf("Wonderful life"); } int main(){    //test atexit ,call user defined function    atexit(second);    atexit(first); ... Read More

Functions fread and fwrite Used in Files in C

Bhanu Priya
Updated on 06-Mar-2021 07:46:28

23K+ Views

ProblemWrite a C program for storing the details of 5 students into a file and print the same using fread() and fwrite()SolutionThe fread() function reads the entire record at a time.Syntaxfread( & structure variable, size of (structure variable), no of records, file pointer);Examplestruct emp{    int eno;    char ename [30];    float sal; } e; FILE *fp; fread (&e, sizeof (e), 1, fp);The fwrite() function writes an entire record at a time.Syntaxfwrite( & structure variable , size of structure variable, no of records, file pointer);Examplestruct emp{    int eno:    char ename [30];    float sal; } e; FILE ... Read More

Concatenating N Characters from Source String to Destination String in C

Bhanu Priya
Updated on 06-Mar-2021 07:44:01

872 Views

ProblemWrite a C program to concatenate n characters from source string to destination string using strncat library functionSolutionThe strcat functionThis function is used for combining or concatenating two strings.The length of the destination string must be greater than the source string.The resultant concatenated string will be in the source string.Syntaxstrcat (Destination String, Source string);Example 1#include main(){    char a[50] = "Hello";    char b[20] = "Good Morning";    clrscr ( );    strcat (a, b);    printf("concatenated string = %s", a);    getch ( ); }OutputConcatenated string = Hello Good MorningThe strncat functionThis function is used for combining or ... Read More

Compare Two Strings Using strncmp Library Function in C

Bhanu Priya
Updated on 06-Mar-2021 07:39:52

3K+ Views

Strncmp is a predefined library function present in string.h file, it used to compare two strings and display which string is greater.The strcmp fucntion (String comparison)This function compares 2 strings. It returns the ASCII difference of the first two non– matching characters in both the strings.Syntaxint strcmp (string1, string2);If the difference is equal to zero, then string1 = string2.If the difference is positive, then string1> string2.If the difference is negative, then string1 0) {       printf("%s is greater than %s", string1, string2);    } else {       printf("%s is less than %s", string1, string2);    } ... Read More

Read Data from File and Display in C

Bhanu Priya
Updated on 06-Mar-2021 07:36:39

17K+ Views

ProblemHow to read a series of items that are present in a file and display the data in columns or tabular form using C ProgrammingSolutionCreate a file in write mode and write some series of information in the file and close it again open and display the series of data in columns on the console.Write mode of opening the fileFILE *fp; fp =fopen ("sample.txt", "w");If the file does not exist, then a new file will be created.If the file exists, then old content gets erased & current content will be stored.Read mode of opening the file   FILE *fp fp =fopen ... Read More

Find Total Number of Lines in an Existing File using C

Bhanu Priya
Updated on 06-Mar-2021 07:33:00

344 Views

Open a file in reading mode. If the file exists, then write a code to count the number of lines in a file. If the file does not exist, it displays an error that the file is not there.The file is a collection of records (or) It is a place on the hard disk where data is stored permanently.Following are the operations performed on files −Naming the fileOpening the fileReading from the fileWriting into the fileClosing the fileSyntaxFollowing is the syntax for opening and naming a file −1) FILE *File pointer;    Eg : FILE * fptr; 2) File pointer ... Read More

Advertisements