Program using strcat() function.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str1[10]="jbrec";
char str2[]="ece";
strcat(str1,str2);
printf("%s\n",str1);
printf("%s\n",str2);
getch();
}
OUTPUT : jbrecece
ece
7 : strrev(string) - String Reverse :This function is used to reverse a string. This function takes
only one argument and return one argument.
Syntax : strrev(string);
Ex : Program using strrev() function
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
C PROGRAMMING Page 131
,char str[20];
printf("Enter the string:");
scanf("%s",str);
printf("The string reversed is:%s",strrev(str));
getch();
}
OUTPUT : Enter the string :subbareddy
The string reversed is : ydderabbus
UNIT – III
FUNCTIONS:
User‐Defined Functions
Definition: A function is a block of code/group of statements/self contained block of statements/
basic building blocks in a program that performs a particular task. It is also known
as procedure or subroutine or module, in other programming languages.
To perform any task, we can create function. A function can be called many times. It
provides modularity and code reusability.
C PROGRAMMING Page 132
, Advantage of functions
1) Code Reusability
By creating functions in C, you can call it many times. So we don't need to write the same code
again and again.
2) Code optimization
It makes the code optimized we don't need to write much code.
3) Easily to debug the program.
Example: Suppose, you have to check 3 numbers (781, 883 and 531) whether it is prime number or
not. Without using function, you need to write the prime number logic 3 times. So, there is repetition of
code.
But if you use functions, you need to write the logic only once and you can reuse it several times.
Types of Functions
There are two types of functions in C programming:
1. Library Functions: are the functions which are declared in the C header files such as
scanf(), printf(), gets(), puts(), ceil(), floor() etc. You just need to include appropriate
header files to use these functions. These are already declared and defined in C
libraries. oints to be Remembered
System defined functions are declared in header files
System defined functions are implemented in .dll files. (DLL stands for Dynamic Link
Library).
To use system defined functions the respective header file must be included.
2. User-defined functions: are the functions which are created by the C programmer, so
that he/she can use it many times. It reduces complexity of a big program and optimizes
the code. Depending upon the complexity and requirement of the program, you can create
as many user-defined functions as you want.
C PROGRAMMING Page 133
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str1[10]="jbrec";
char str2[]="ece";
strcat(str1,str2);
printf("%s\n",str1);
printf("%s\n",str2);
getch();
}
OUTPUT : jbrecece
ece
7 : strrev(string) - String Reverse :This function is used to reverse a string. This function takes
only one argument and return one argument.
Syntax : strrev(string);
Ex : Program using strrev() function
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
C PROGRAMMING Page 131
,char str[20];
printf("Enter the string:");
scanf("%s",str);
printf("The string reversed is:%s",strrev(str));
getch();
}
OUTPUT : Enter the string :subbareddy
The string reversed is : ydderabbus
UNIT – III
FUNCTIONS:
User‐Defined Functions
Definition: A function is a block of code/group of statements/self contained block of statements/
basic building blocks in a program that performs a particular task. It is also known
as procedure or subroutine or module, in other programming languages.
To perform any task, we can create function. A function can be called many times. It
provides modularity and code reusability.
C PROGRAMMING Page 132
, Advantage of functions
1) Code Reusability
By creating functions in C, you can call it many times. So we don't need to write the same code
again and again.
2) Code optimization
It makes the code optimized we don't need to write much code.
3) Easily to debug the program.
Example: Suppose, you have to check 3 numbers (781, 883 and 531) whether it is prime number or
not. Without using function, you need to write the prime number logic 3 times. So, there is repetition of
code.
But if you use functions, you need to write the logic only once and you can reuse it several times.
Types of Functions
There are two types of functions in C programming:
1. Library Functions: are the functions which are declared in the C header files such as
scanf(), printf(), gets(), puts(), ceil(), floor() etc. You just need to include appropriate
header files to use these functions. These are already declared and defined in C
libraries. oints to be Remembered
System defined functions are declared in header files
System defined functions are implemented in .dll files. (DLL stands for Dynamic Link
Library).
To use system defined functions the respective header file must be included.
2. User-defined functions: are the functions which are created by the C programmer, so
that he/she can use it many times. It reduces complexity of a big program and optimizes
the code. Depending upon the complexity and requirement of the program, you can create
as many user-defined functions as you want.
C PROGRAMMING Page 133