0% found this document useful (0 votes)
14 views8 pages

Ex No 6 FUNDAMENTALS OF C PROGRAMMING

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views8 pages

Ex No 6 FUNDAMENTALS OF C PROGRAMMING

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

20CS1003L – Fundamentals of programming for URK21C

Problem Solving Lab S

Ex. No. 6 Strings


Date of NAME :VENKATESAN G
05/04/2022
Exercise REG NO :URK21BT1053

Aim:
. To write a C program to find the length of the entered string using string handling function.

Algorithm:

1. start the program


2. declare the character array to store the string
3. read the string
4. find the length of the string using strlen() library function
5. print the length of the string
6. stop the program

Description:
● A sequence of one or more characters enclosed in double quotes.
● Stored using character arrays
● Automatically terminated with a null character (\0)

Declaration of String
data_type string_name[size];
Example: char s[5];

Initialization of String
Method 1:

1
20CS1003L – Fundamentals of programming for URK21C
Problem Solving Lab S

char c[] = "abcd";

Method 2:
char c[50] = "abcd";

Method 3:
char c[] = {'a', 'b', 'c', 'd', '\0'};
Method 4:
char c[5] = {'a', 'b', 'c', 'd', '\0'};

Program:
Read String from the user:
#include <stdio.h>
int main()
{
char name[20];
printf("Enter name: ");
scanf("%s", name);
printf("Your name is %s.", name);
return 0;
}

Sample Input and Output:


Enter name: Dennis Ritchie
Your name is Dennis.

String Functions:

2
20CS1003L – Fundamentals of programming for URK21C
Problem Solving Lab S

3
20CS1003L – Fundamentals of programming for URK21C
Problem Solving Lab S

List of experiments:

1. Write a program to reverse a given string.


2. Write a program to find the length of the string.

OUTPUT :

4
20CS1003L – Fundamentals of programming for URK21C
Problem Solving Lab S

3. Write a program to concatenate two strings.

5
20CS1003L – Fundamentals of programming for URK21C
Problem Solving Lab S

OUTPUT :

4. Write a program to copy the string from P to Q.

6
20CS1003L – Fundamentals of programming for URK21C
Problem Solving Lab S

OUTPUT :

5. Write a program to find the whether the given two strings are equal or not.

7
20CS1003L – Fundamentals of programming for URK21C
Problem Solving Lab S

OUTPUT :

Result:
THE PROGRAMS ARE EXECUTED AND VERIFIED.

You might also like