1 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

SriRaghavendraEducationalInstitutionsSociety(R)

www.skit.org.in

Title: - Introduction to C

COaddressed:CO2

Course: BESCK204E –Introduction to C

Presented by: Dr Nirmala S Guptha

Department:CSE

2 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

2

/skit.org.in

Introduction to C Programming :

3 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

3

/skit.org.in

HISTORY OF C :

(Europe)

ALGOL1960

International Group (Europe)

Combined BCPL Lang.)

1967 Martin Richards

(Basic Programming Combined

B 1970

Version of UNIX)

Ken Thompson( first version of

C 1972

Dennis Ritchie (C)

4 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

4

/skit.org.in

History of C --- contd..

K&R C 1978

Kernighan & Ritchie

ANSI C 1989 ANSI committee

(American National Standards Institute) ANSI/ISO C 1990 ISO committee (International Standards Organization)

K&R C 1978

Kernighan & Ritchie

ANSI C 1989 ANSI committee

(American National Standards Institute) ANSI/ISO C 1990 ISO committee (International Standards Organization)

5 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

5

/skit.org.in

WHY LEARN C?

C is easy to learn

C is portable

C is middle level language

6 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

6

/skit.org.in

Characteristics of C :

  • C Compiler Combines the features of assembly language and high-level language
  • Best suited for writing programs for system

software and business

Characteristics

  • High level language- Not worry about the machine code
  • Small Size – C has 32 keywords
  • Extensive use of function calls
  • Well suited for Structed programming language
  • Supports loose typing

7 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

7

/skit.org.in

Characteristics of C :

  • Stable language – ANSI C was created in 1983 and since then no revision
  • Quick language
  • Facilitates low level programming
  • Core Language – C++, Java, Perl
  • C is portable language
  • C is an extensible language

8 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

8

/skit.org.in

USES of C :

  • Used System programming
  • Used System programming
  • End – user application programming

9 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

9

/skit.org.in

10 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

STRUCTURE : C PROGRAM

1

11 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

ILLUSTRATED VERSION OF A PROGRAM:

1

12 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Writing the first C Program:

# Include <stdio.h> Int main()

{

printf(“\n welcome to C programming”);

}

1

13 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Parts of a Program:

#include <stdio.h>

int x;

int main () {

int y; Local Declaration

printf("Enter x and y: "); scanf(&x,&y);

printf("Sum is %d\n",x+y);

}

Preprocessor Directive

Global Declaration

Function

Statements

1

14 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Comments:

Text between /* and */

Used to “document” the code for the human reader Ignored by compiler (not part of program)

Have to be careful

comments may cover multiple lines

ends as soon as */ encountered (so no internal comments - /* An /* internal */ comment */)

// single line

1

15 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Comment Example:

#include <stdio.h>

/* This comment covers

  • multiple lines
  • in the program.

*/

int main () /* The main header */ {

/* No local declarations */

printf(“Too many comments\n”);

} /* end of main */

1

16 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Files used in a C program:

Files in a C program

  • Source file

  • Header File

  • Object file

    • Executable file

1

17 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Source Code File:

  • Containing the source code of the program
  • The file extension of the C source code is .c
  • C source code file contains main function and may be other functions
  • The main() is the starting point of the c program

1

18 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Header file:

  • Use same subroutine in different programs
  • Compile the source code of the subroutine once, link object file to any other program
  • Header file with .h extension

1

19 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Standard Header Files:

Predefined files

String.h – string handling functions

Stdlib.h – Some library function (miscellaneous functions)

Stdio.h – Standardized input and output functions

Math.h – Mathematical functions Alloc.h – Dynamic memory allocation

Conio.h – Clearing the screen and character input

1

20 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Object File:

  • Object files are generated by the compiler as a result of processing the source code file
  • Object file contain compact binary code of the function definitions
  • Linker uses object files to produce an executable

file by combining the object files together

  • Object files - .o or .obj extension

2

21 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Binary Executable File:

  • Binary executable file is generated by the linker
  • The linker links the various object files to produce a binary file that can be directly executed
  • .exe extension - windows

2

22 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

C Tokens:

  • Tokens are the basic building blocks in C language

2

23 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

2

24 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Character set in C:

2

25 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

2

26 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

2

27 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

2

28 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

2

29 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

2

30 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

3

31 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

3

32 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

3

33 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

3

34 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

KEY WORDS

  • Keywords are system defined identifiers.
  • Keywords are reserved words.
  • They have specific meaning in the language and cannot be used by the programmer as a variable or constant name.
  • C is case sensitive.
  • 32 Keywords.

3

35 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

3

36 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

3

37 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

3

38 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

3

39 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

CLASSIFICATION :DATA TYPE

3

40 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Data type

Keywords Used

Size in bytes

Range

Use

Character

char

1

-128 to

127

To store character

Integer

int

2

-32768 to

32767

To store integer number

Floating Point

float

4

3.4E-38 to

3.4E+38

To store decimal number

Double

double

8

1.7E-308 to 1.7E308

To store big floating-point number

Valueless

void

0

Valueless

-

4

Basic Data Types

41 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Examples - Character

#include <stdio.h> void main()

{

char c = 'b';

printf("The character value is: %c \n", c);

}

4

42 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Example - Integer

#include <stdio.h> void main()

{

int i = 5;

printf("The integer value is: %d \n", i);

}

4

43 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Examples - Float

#include <stdio.h>

void main()

{

float f = 7.2357;

printf("The float value is: %f \n", f);

}

4

44 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Example – Double

#include <stdio.h> void main()

{

double d = 71.2357455;

printf("The double value is: %lf \n", d);

}

4

45 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

4

46 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

4

47 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

4

48 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Variables Types

Variables

Numeric Variable

4

Character Variables

49 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

VARIABLES

  • A variable is a container(storage area) to hold data.
  • All variables have three important attributes:
    • data type
    • name
    • value
  • Eg: int a = 10; float b = 2.5; char c = ‘f’;

4

50 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

5

51 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

CONSTANT

A constant is a value or an identifier whose value cannot be altered in a program. For example: 1, 2.5

An identifier also can be defined as a constant. eg. const double PI = 3.14

Here, value of PI is a constant.

5

52 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Constant Declaration

  • To declare a constant, precede the normal variable declaration with const keyword and assign it a value.
  • For example,

const float pi = 3.14;

  • Another way to designate a constant is to use the pre-processor command

define.

#define PI 3.14159

When the preprocessor reformats the program to be compiled by the compiler, it replaces each defined name with its corresponding value wherever it is found in the source program.

5

53 of 75

3/19/2025

/skit.org.in

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

TYPES OF CONSTANTS

Integer constant eg: 1

Floating-point

constant eg: 2.5 Character constant eg: ’a’

String constant eg:

”good”

5

54 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Input/Output in C

5

55 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

STREAMS

  • A stream acts in two ways. It is the source of data as well as the destination of data.
  • C programs input data and output data from a stream. Streams are associated with a physical device such as the monitor or with a file stored on the secondary memory.
  • In a text stream, sequence of characters is divided into lines with each line being terminated with a new-line character (\n). On the other hand, a binary stream contains data values using their

memory representation.

  • Although, we can do input/output from the keyboard/monitor or from any.

Keyboard

Data

Monitor

Input text stream

Data

Input text stream

Streams in a C program

Text Stream

Binary Stream

5

56 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Data I/O

  1. Formatted Input/output functions

  • Unformatted Input/output functions

5

57 of 75

3/19/2025

/skit.org.in

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

scanf() - input function

printf() - output function

5

Formatted Input and Output Functions

scanf() - input function

Formatted Input and Output Functions

58 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Printf()

Output function

General form: printf(“control_string or format

specifier”,variable1,variable2, variable3,...);

Example:

printf(“The numbers are %d and

%d”,number1,number2);

5

59 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Format Specifiers

5

60 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Parts of conversion specifier field for printf()

precision indicates the number of characters used after the decimal point. The precision option is only used with floats or strings.

Default precision value is 6

The percent sign and conversion code are required

Other modifiers such as width and precision are optional.

width specifies the total number of characters used to display the value

6

61 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Size modifiers used in printf()

6

62 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Examples

6

printf(“number=%3d\n”, 10);

printf(“number=%2d\n”, 10);

printf(“number=%1d\n”, 10);

printf(“number=%7.2f\n”, 5.4321);

printf(“number=%.2f\n”, 5.4391);

printf(“number=%.9f\n”, 5.4321);

printf(“number=%f\n”, 5.4321);

63 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Example

# include <stdio.h>

int main()

{

printf(“number=%3d\n”, 10);

printf(“number=%2d\n”, 10);

printf(“number=%1d\n”, 10);

printf(“number=%7.2f\n”, 5.4321);

printf(“number=%.2f\n”, 5.4391);

printf(“number=%.9f\n”, 5.4321);

printf(“number=%f\n”, 5.4321);

}

6

64 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Flag

Meaning

-

Left justify the display

+

Display positive or negative sign of value

Space

Display space if there is no sign

0

Pad with leading zeros

#

Use alternate form of specifier

6

Flag characters used in printf()

65 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Example

printf(“number=%06.1f\n”, 5.5);

printf(“%+6.1f=number\n”, 5.5);

6

66 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Example with strings

#include<stdio.h> int main()

{

printf(“%s”,“hello”);

printf(“\n%3s”,“hello”);

printf(“\n%10s”,“hello”);

printf(“\n%-10s”,“hello”);

printf(“\n%10.3s”,“hello”); return 0; }

}

6

67 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

scanf()

General form:

scanf(“control_string”, variable1_address, variable2_address,...);

scanf() returns the number of input fields successfully scanned, converted, and stored

Example: scanf(“%d%d”,&num1,&num2);

6

68 of 75

3/19/2025

/skit.org.in

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

gets() getchar() getch() getche()

Output functions puts() putchar() putch() puts()

6

  1. Unformatted Input/output functions
    1. Data Input and Output

Input functions

  • The I/O library functions are listed in the “header” file <stdio.h>.
  • Types:
    • Unformatted Input/output functions
    • Formatted Input/output functions

69 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

Output:

Enter a character k c = k

6

getchar()

Reads a single character from the input data stream; but does not return the character to the program until the ‘\n’ ( or ) enter key is pressed.

Syntax:-

variable = getchar();

Example:- char c;

c = getchar();

Program #include<stdio.h> void main()

{

char c;

printf(“Enter a character”); c=getchar();

printf(“c = %c ”,c);

}

70 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

getch() and getche()

These functions read any alphanumeric character from the standard input device

The character entered is not displayed by the getch() function until enter is pressed

The getche() accepts and displays the character.

The getch() accepts but does not display the character. Syntax:

getche();

getch();

7

71 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

getch() and getche() - Program

#include<stdio.h> void main()

{

printf(“Enter two alphabets:”); getche();

getch();

}

Output

Enter two alphabets a b a

7

72 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

putchar()

7

This function prints one character on the screen at a time which is read by standard input.

Syntax:

putchar( variable name); Example:

char c= ‘c’; putchar(c);

#include<stdio.h> void main()

{

char ch;

printf(“Enter a character: ”); scanf(“%c”, &ch); putchar(ch);

}

Output

Enter a character: r r

73 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

putch()

This function prints any alphanumeric character taken by the standard input device

Syntax:

putch( variable name);

7

Example: char c= ‘c’; putch(c);

Program #include<stdio.h> void main()

{

char ch;

printf(“Press any key to continue”); ch = getch();

printf(“ you pressed:”); putch(ch);

}

Output:

Press any key to continue You pressed : e

74 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

3/19/2025

/skit.org.in

puts()

This function prints the string or character array.

It is opposite to gets()

Syntax

char str[length of string in number];

gets(str); puts(str);

7

75 of 75

SriKrishnaInstituteofTechnology

(ApprovedbyAICTE,AccreditedbyNAAC,AffiliatedtoVTU,Karnataka)

gets()

String I/O

This function is used for

accepting any string( stream of characters) until enter key is

pressed

Syntax

char str[length of string in number];

gets(str); Example:

char name[15]; gets(name);

3/19/2025

/skit.org.in

7

Program #include<stdio.h> void main()

{

char ch[30];

printf(“Enter the string:”); gets(ch);

printf(“Entered string: %s”, ch);

}

Output:

Enter the string: Use of data! Entered string: Use of data!