Program to accepting and displaying numbers in reverse order */
#define N 10
int a[N], k;
for(k = 0; k < N; k++)
printf("\nEneter The Element For a[%d] : ", k);
printf("\nWriting The Numbers in the Reverse Order...Please Wait...\n");
for(k = N - 1; k >= 0; k--)
printf("\nThe Element in Index a[%d] = %d", k, a[k]);
Handling Strings and Characters in Arrays
A STRING is an ARRAY of CHARACTERS.
In ‘C’ a STRING is defined as a GROUP of COLLECTED CHARACTERS in
between DOUBLE QUOTATION MARKS.
Example: “This is Sample String”
DOUBLE QUOTATION marks do not form part of the character string.
A STRING can be of ANY LENGTH, hence the end of the string is marked with
the SINGLE CHARACTER ‘\0’, which is termed as NULL CHARACTER, having
the ASCII value of ZERO.
The declaration of a STRING is similar to the NUMERIC ARRAY.
char MyString = “COLLEGE” ;
Every STRING must be TERMINATED by a NULL, hence any STRING must be
defined in such a way that it can hold one BYTE LARGER THAN THE LARGEST
STRING, to make a room for the NULL.
A STRING can be initialized at the time of array declaration or using a loop
in the program.
If the number of characters in the string exceed the maximum size, the
string is truncated.
If the number of characters in the string are less than the maximum size,
then the compiler allocates the NULL character at the first empty element
of the string.
Functions used in INPUT and OUTPUT of strings:
It is used to accept strings from the keyboard.
The format specifiers used are “%s” or “%nc ”
“ % ne ” is used for inputting a string, until the n’th character in keyed
while using scanf(), spaces cannot be embedded into the STRING.
Example: INPUT : “This is Sample String”
OUTPUT : THIS
Scanf () function cannot be used to input white spaces, hence the only
operation it can perform is on continuious string.
It is used to display the strings.
→the format specifiers used to print a string is “%s” OR “%n.ds”.
1. n →specifies the field width to be displayed
2. d →specifies that only first ‘d’ character of the string have to be
It can also print the white spaces.
Prints character by character and terminates the display when the NULL
character is encountered.
It is a function to accept strings from the standard input device.
It can take spaces as input from the keyboard.
char string ;
It is a function to display the strings on to the standard output device.
Automatically puts a new line character ‘\n’ after display of each string.
Can handle only one string at a time.
Initializing a character array, accept string into it and display.
printf("\nEnter The Data : ");
scanf ("%s", string);
printf ("\n%s", string);
puts("\nEnter Data Again : ");
puts("The String is : ");
To read a line of text
char string, ch;
int k = 0;
while((ch = getch()) != '\r')
if (ch >= 'a'&& ch <= 'z')
ch = ch - 32;
string[k++] = ch;
if (k > 80)
string[k] = '\0';
To find length of a string
printf("\nEnter Your Data...\n");
printf("\nProcessing The String...");
for (k = 0; string[k] != '\0'; k++);
printf ("\nThe Length of %s is %d", string, k);