topics :
1)comparing strings
2)determining string lengths.
3) combining strings
4)structures.
Comparing 2 strings:>> In c it is not possible to directly compare two strings so a statement like if (string1==string2) is not valid.
Most c libraries contain a function called the strcmp().This is used to compare two strings in the following manner.
if(strcmp(name1,name2)==0)
puts("The names are the same");
else
puts("The names are not the same.");
Determining string length.:>> This is done using the strlen() function.
a simple programming bit showing this function looks like this:
gets(name);
count=strlen(name);
printf("the string %s has %d characters",name,count);
Combining strings:>>We use the function strcpy() an example follows:
Example-11
strcpy(name,"Adam");
strcpy(name1,"and eve");
strcat(name,name1);
puts(name);
The assumption being that adam and eve are two values of the variables name1 and name2. The end result is the combination of the 2 names.
What are structures?
A structure variable is a collection of other variables comprising different types.
What are pointers?
Ponters are variables which refer to the memory locations of other variables.
This is how a structure is defined.
example-12
struct cd
{
char name[20];
char description[40];
char category[12];
float cost;
int number;
};
main()
Notice how the main function comes after the definition of the structure. In the example above the cd was a cd disk and I was writing the definition of a cd collection program.
No comments:
Post a Comment