Copy Contents of One File to Another in C

Bhanu Priya
Updated on 11-Mar-2021 07:09:19

23K+ Views

File is a collection of records (or) is a place on hard disk, where data is stored permanently. By using C commands, we can access the files in different ways.Operations on filesThe operations that can be carried out on files in C language are as follows −Naming the file.Opening the file.Reading from the file.Writing into the file.Closing the file.SyntaxThe syntax for opening and naming file is as follows −FILE *File pointer;For example, FILE * fptr;File pointer = fopen ("File name”, "mode”);For example, fptr = fopen ("sample.txt”, "r”);FILE *fp; fp = fopen ("sample.txt”, "w”);The syntax for reading from file is as ... Read More

High-Level I/O Functions in C Language

Bhanu Priya
Updated on 11-Mar-2021 07:03:50

5K+ Views

I/O refers to the input - output functions in C language.High level I/OThese are easily understood by human beingsThe advantage is portability.Low level I/OThese are easily understood by computer.The advantage is that execution time is less.The disadvantage is that Non portability.High level I/O FunctionsThe high level input - output (I/O) functions are explained below −FunctionDescriptionfprintf ( )write data into a filefscanf ( )read data from a fileputc ( )/ fputc()write a character into a filegetc ( ) /fgetc()read a character from a fileputw ( )write a number into a filegetw ( )read number from a filefputs ( )write a string ... Read More

Meaning of Line 'Yug Shahstra Yojan Par Bhanu' from Hanuman Chalisa

Knowledge base
Updated on 10-Mar-2021 18:57:59

43K+ Views

Lord Hanuman is the great central characters  of the Indian epic Ramayana. Hanuman is well-known for his strength and he is immune to all sorts of weapons. He has got extreme speed (manojavam, marutha tulya vegam) effulgence, wisdom, no fear of death (Chiranjeevi), has won over the senses that lure. He has the knowledge of Eight Siddhis and Nine devotions. Even the world’s dangerous weapon Brahmastra can never harm him. He is the most powerful yet very obedient devotee of Shri Rama.The accurate prediction of distance from Earth to Sun:It was written in Hanuman Chalisa, “Yug Sahasra Yojana Par Bhanu, ... Read More

Form Cumulative Sum List in Python

pawandeep
Updated on 10-Mar-2021 14:26:20

3K+ Views

The cumulative sum till ith element refers to the total sum from 0th to ith element.The program statement is to form a new list from a given list. The ith element in the new list will be the cumulative sum from 0 to ith element in the given list.For example, Input[10, 20, 30, 40, 50]Output[10, 30, 60, 100, 150]Input[1, 2, 3, 4, 5]Output[1, 3, 6, 10, 15]Following is a program to form a cumulative sum list using the input list −The input list is passed to the function cumSum() which returns the cumulative sum list.We declare an empty list cum_list ... Read More

Round Off a Number in Python

pawandeep
Updated on 10-Mar-2021 14:18:23

861 Views

Python has an inbuilt round() function to round off a number.The round() method in Python takes two parameters −The first one is the number to be rounded off.The second one specifies the number of digits to which the number must be rounded off.Here, the second parameter is optional.If second parameter is not specified, then the round() method returns the integer using floor() and ceil().It will look for the digits after the decimal.If those are less than 5, it returns the floor() of the number passed.Whereas if the digits after decimal are greater than 5, it returns the ceil() of the ... Read More

Print Pattern in Python

pawandeep
Updated on 10-Mar-2021 14:15:23

2K+ Views

Patterns in Python can be printed using nested for loops. The outer loop is used to iterate through the number of rows whereas the inner loop is used to handle the number of columns. The print statement is modified to form various patterns according to the requirement.The patterns can be star patterns, number patterns, alphabet patterns. The patterns can be of different shapes, triangle, pyramids, etc.ExampleAll these patterns can be printed with the help of for loops with modified print statements which forms these different patterns.The basic idea between the printing of these patterns is the same with slight differences.We ... Read More

Reverse a Number in Python

pawandeep
Updated on 10-Mar-2021 14:12:28

2K+ Views

Reversing an integer number is an easy task. We may encounter certain scenarios where it will be required to reverse a number.Input: 12345 Output: 54321There are two ways, we can reverse a number −Convert the number into a string, reverse the string and reconvert it into an integerReverse mathematically without converting into a stringConvert into string and ReverseThis method of reversing a number is easy and doesn’t require any logic. We will simply convert the number into string and reverse it and then reconvert the reversed string into integer. We can use any suitable method for reversing the string.Example Live Demodef ... Read More

Create a Dictionary in Python

pawandeep
Updated on 10-Mar-2021 14:05:15

2K+ Views

A Dictionary in Python is a type of data structure.It consists of a collection of key-value pairs. Each key in the dictionary is unique. Each unique key in the dictionary is associated to its value. Thus, Dictionary holds key : value pairs.We will be discussing how to create a dictionary in Python.Create a DictionaryA dictionary in Python can be created by placing various key: value pairs inside curly braces .The key:value pairs are separated from each other using commas(, ). The values in the dictionary can be of any datatype and can be duplicated. However, the keys in the dictionary ... Read More

Convert int to String in Python

pawandeep
Updated on 10-Mar-2021 14:03:57

1K+ Views

Type conversion is at times needed when the user wants to convert one data type into another data type according to requirement.Python has in-built function str() to convert an integer to a string. We will be discussing various other methods in addition to this to convert int into string in Python.Using str()This is the most commonly used method to convert int into string in Python.The str() takes integer variable as a parameter and converts it into a string.Syntaxstr(integer variable)Example Live Demonum=2 print("Datatype before conversion", type(num)) num=str(num) print(num) print("Datatype after conversion", type(num))OutputDatatype before conversion 2 Datatype after conversion The type() function ... Read More

Convert List to String in Python

pawandeep
Updated on 10-Mar-2021 13:59:46

2K+ Views

There may be some situations, where we need to convert a list into a string. We will discuss different methods to do the same.IterationIterate through the list and append the elements to the string to convert list into a string. We will use for-in loop to iterate through the list elements.Example Live Demolist1=["Welcome", "To", "Tutorials", "Point"] string1="" for i in list1:    string1=string1+i string2="" for i in list1:    string2=string2+i+" " print(string1) print(string2)OutputWelcomeToTutorialsPoint Welcome To Tutorials PointUsing .join() methodThe list will be passed as a parameter inside the join method.Example Live Demolist1=["Welcome", "To", "Tutorials", "Point"] string1="" print(string1.join(list1)) string2=" " print(string2.join(list1))OutputWelcomeToTutorialsPoint Welcome To ... Read More

Advertisements