You are on page 1of 10

Unformatted Input/Output fucntion

Unformatted Input/Output fucntion is the form of input/output. The Unformatted input/output transfers the internal binary representation of the data directly between memory and the file.

Advantages of Unformatted I/O


Unformatted input/output is the very simple and most efficient form of input/output. It is usually the most easy way to store data. Unformatted input/output fucntion is the most portable form of input/output. Unformatted data files can only be moved easily to and from computers that share the same internal data representation.

The some unformatted input /output functions are as follows getchar ():Getchar () function is usesd to get read a single character from standard input device. Syntax: - Variable Name= getchar ();

2. putchar ():Putchar () function is an output function used to transmit a single character on screen. Syntax:- putchar (variable Name); Char d; D=A; Putchar (d);

getche ():The getche() return the character that that has been typed and display it on the screen.

Syntax: Variable Name= getche (); Char rec; rec = getche ();

getch ():The getch() function is used to read a character from the keyboard and it does not display it to the screen.

puts ():The put () function works exactly opposite to gets() function. The put() is used to get output a string on the screen. Syntax: puts (Sting Name);

Formatted I/O function


Formatted output change the internal binary representation of the data to ASCII characters that are written to the output file. Formatted input reads characters from the input file and also change them to binary form. Formatted I/O fucntion may be either "Free" format or "Explicit" format.

Advantages Formatted I/O


Formatted input/output is most portable. It is a simple process to move formatted data files to various computers, even computers running different operating systems, as long as they all use the ASCII character set. Human can easily readable Formatted files. Human readable and also can be typed to the terminal screen or edited with a text editor.

Farmated I/O function are:printf ():The printf() function is used to send the formatted output to the output device. Syntax: printf (Format String, Variable List);

Scanf ():The scanf() function allow us to supply the input in the fixed format. Syntax :- (format string ,list of address of variable);

Q2. What do you mean by type conversion? What is EOF? How is it entered from keyboard? Explain both with example. Ans:-Type Conversion:When single expression contain different variables different data types. Then we can say it type conversion. In the type conversion the value of expression is promoted/demoted depending on the type of variable on left hand side of=. For example: Int m; Float n; m=4.5; n=5; There are two type of data type conversions in C expression: Implicit Data type Conversion Explicit Data type Conversion

Implicit Data type Conversion:In this type conversion, C complier itself change the data type resultant as pre the data type of operand. Some of rules occur that are used for implicit conversion of

floating and an integer values to developing effective c program that are follows: An arithematetic operation between an integer and integer always yields integer. Operation between INT and REAL the results always in real . For example 2/5=0 and 5.0/2=2.500000 and 2./5.0=0.400000 When operation between real into real the results will be real.

Explicit Data Type Conversion:In c programming when no operator is assumed to be present it must be written explicitly. Example:- m = p.q.r(ab)

EOF Definition:In the function of c standard library the character reading functions such getchar() return a value equal to the symbolic value (macro) EOF to indicate that an End-Of-File condition has occurred. The actual value of EOF is systemdependent and is unequal to any valid character code. EOF is a macro defined as an int with
a negative value. It is normally returned by functions who perform read operations to denote either an error or end of input. Due to variable promotion rules (discussed in detail later), it is important to ensure we use an int to store the return code from these functions, even if the function appears to be returning a char, such as getchar() or fgetc().
int x; while ((x = fgetc(fp)) != EOF) { putchar (x); }

int ch; while ((ch = cin.get()) != EOF) { Printf((char))ch; }

When the file pointer pass then final character, the "fgetc()" function will returns a negative integer value tied to a macro called "EOF." A macro is a redefinition of a value into another readable form. when programmer check for this value by using the "EOF" macro. If the function returns the value, the programmer can halt reading of the file and remove the errors.

Q3. How will you replace blank spaces with zeros using output function in case of integer data type?
Solution: #include<stdio.h> void main() { Int a[10], b,n,m ; printf (enter the no:); scanf (%d,&n); for (m=0; m<n; m++) { scanf(%d,&a[m]); } printf(the no is:); for(m=0;m<n;m++) { If(a[m]==0) { printf(\0); } else { printf(%d,a[m]); }

} }

PART-B
Q4. What will be the output and give its descriptions:

(a) Void main () { int a, b; int sum; printf ("Enter any two integers: "); Scanf ("%d%d", &a,&b); sum = a - ~b -1; printf ("Sum of two integers: %d", sum); }

Output:-Enter any two integers: 5 7


Sum of two integers: 12
Descriptions:- In the above program uses Bitwise operator(~ ones complement operator).when

we enter any int. no. then the this operator convert the int. no. into binary form and again change it to complement and at last the converted no. reconvert into decimal. So, this program is give result us to sum of entered integer no.

(b) #include<stdio.h> #define L 10

Void main () { Auto money=10; Switch (money, money*2) { case L: printf("Willian"); break; case L*2: printf ("Warren"); break; case L*3:printf("Carlos"); break; default: printf("Lawrence"); case L*4:printf ("Inqvar"); break; } }
Output: - Warren Description:- The output will be warren here using switch break statement, when the case L*2 occur the switch statement found case L*2 it true, then it break statement and give the above output.

Q5.To show the importance of else if by making a game in which you have reach coordinates x=0 , y=0 when you are initially at x=10 , y=10. Solution://*Using else if making game in which we have reach coordinate x=0, y=0 when we are initially at x=10, y=10 *//

#include<stdio.h> #include<conio.h> void main() { Char dir;

int x=10,y=10; printf(type m to put); while(dir!=m) { Printf(your location is x=%d,y=%d,x,y); Printf(puess direction (n,e,s,w):); dir=getch(); if(dir==n) y--; elseif(dir==s) y++; elseif(dir==e) x--; elseif(dir==w) x++; } getch(); }

Q6.To Convert the time in seconds to the time in hours, minutes and seconds and then display what time of the day it is?
Solution:-

#include<stdio.h> #include<conio.h> void main () { long int s,h,m,k; clrscr(); printf(Enter the time sec:); scanf(%ld ,&s); h=s/3600; k=s%3600; m=k/60; s=k%60; printf(\n time is %ld hr:%ld sec,h,m,); getch(); }

You might also like