Array 2
Array 2
STRINGS
Strings
Definition
A string is an array of characters.
Any group of characters (except double quote sign) defined between
double quotation marks is a constant string.
Character strings are often used to build meaningful and readable
programs.
The common operations performed on strings are
Reading and writing strings
Combining strings together
Copying one string to another
Comparing strings to another
Extracting a portion of a string ..etc.
05/21/2024 CSE 1001 Department of CSE 2
05/21/2024 CSE 1001 Department of CSE 3
05/21/2024 CSE 1001 Department of CSE 4
Strings
Declaration and initialization
char string_name[size];
The size determines the number of characters in the string_name.
For example
The 5 characters that compose the word "Hello" plus a final null
character ('\0') which specifies the end of the
In the second case, when using double quotes (") null character ('\0') is
appended automatically.
int main() {
printf(“%s”,question);
scanf(“%s”, yourname);
#include <stdio.h>
int main()
To read everything that you enter from the keyboard until the
ENTER key is pressed (including space).
Syntax:
gets(string) ;
#include<string.h>
int main()
{ {
variable str
printf("\nEnter a string:\n“);
The function will continue to accept characters until enter key is pressed.