Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

DEFINITION

Working with strings in C involves using character arrays, also known as C-strings.
C-strings are sequences of characters terminated by a null character ('\0').
Here are some common operations and functions for working with C-strings in C

DECLARING STRING VARIABLES INITIALIZING STRING VARIABLES


char string_name[ size ]; char city[9] = “NEW YORK”;
Example:
char city ={‘N’,’E’,’W’,’ ‘, ‘Y’,’O’,’R’,’K’,’\0’};

READING STRINGS FROM TERMINAL WRITING STRINGS TO SCREEN


The printf() function with %s format
The input function scanf() with %s format
specifier can be used to display the
specification can be used to read an array
strings on the screen.
of characters (String).
Example:
Example: printf (“%s”, subject);
char subject;
scanf (“%s”, subject); Syntax:
puts(string);
Syntax:
gets(string); Example:
puts(“Computer science”)
Example:
char str[25];
gets(str1);

INPUT AND OUTPUT

ARITHMETIC OPERATIONS ON CHARACTERS


C allows us to manipulate characters the same way we do with
numbers. Whenever a character constant or character variable is used
in an expression, it is automatically converted into an integer value by the system.

atoi() function

atof() function

atol() function

You might also like