Advertisement

Discussion of array


An array is a group of related data items that share a common name. For instance, we
can define array name salary to represent a set of salary of a group of employees. A particular
value is indicated by writing a number called index number or subscript in brackets after the
array name.
Eg: salary[10]
ONE DIMENSIONAL ARRAY
int number[5];
The values to array elements can be assigned as follows.
Eg:
 number[0] = 35;
number[1] = 40;
number[2] = 20;
This types of array can also be::
1) float height[50];
2) int group[10];
3)char name[10]

STRING - HANDLING FUNCTIONS
Function                                Action
strcat( )                            Concatenates two strings
strcmp( )                         Compares two strings
strcpy( )                          Copies one string over another
strlen( )                          Finds the length of the string

Eg::
Program
/*Illustration of string-handling functions*/
#include<string.h>
main()
{clrscr();
char s1[20],s2[20],s3[20];
int x, l1, l2, l3;
printf(“Enter two string constants \n”);
printf(“?”);
scanf(“%s %s”, s1, s2);
x = strcmp(s1, s2);
if(x != 0)
printf(“Strings are not equal \n”);
strcat(s1, s2);
else
printf(“Strings are equal \n”);
strcpy(s3,s1);
l1 = strlen(s1);
l2 = strlen(s2);
l3 = strlen(s3);
printf(“\ns1 = %s \t length = %d characters \n”,s1, l1);
printf(“\ns2= %s \t length = %d characters \n”,s2, l2);
printf(“\ns3 = %s \t length = %d characters \n”,s3, l3);
}
OUTPUT
Enter two string constants
? New York
Strings are not equal
s1 = New York length = 7 characters
s2 = York length = 4 characters
s3 = New York length = 7 characters

No comments:

Post a Comment

Please comment bellow. Share your knowledge