Standard String Library functions in string.h in C

FUNCTION USE
strlen Finds the length of the string.
strlwr Converts string to lower case.
strupr Converts string to upper case.
strcat Appends one string at end of another.
strncat Appends first n characters of a string at end of another.
strcpy Copies a string to another.
strncpy Copies first n characters of a string into another.
strcmp Compares two strings
strncmp Compares first n characters of two strings.
strcmpi Compares two strings without regards to case.
stricmp Compares two strings without regards to case.
strnicmp Compares first n characters of a string without regards to case.
strdup Duplicates a string.
strchr Finds first occurrence of a given character in a string.
strrchr Finds last occurrence of a given character in a string.
strstr Finds first occurrence of a given string in a string.
strset Sets all characters of a string to given character.

 

strnset Sets first n characters of a string to given character.
strrev Reverses the string.
   

Ways to include a file in C

There are two ways of including a file in C using #include statement:

#include “filename”

This command would look for the file in the current directory as well as the specified list of directories as mentioned in the include search path that might have been setup.

 

#include <filename>

This command would look for the file on the specified list of directories only.

 

 

 

Adding Functions to Library in C

This might be known to many but  I recently tried it and got it working.

Suppose you make a function in C(for example here we take a simple function which calculates the square of a number).

Its a fairly simple one and I want to add in in a library thus making its reuse possible.

(Please note I am taking a very simple scenario because the actual program is not the point of focus here, but the procedure is)

The function:

int square(int n)

{

return n*n;

}

Compile the file:

Compile the file in which you have written this function. Lets call it “sqr.c”. A new file called “sqr.obj” is created contained compiled code.

Add the function to Library:

Add the function to the library “maths.lib” using the following command.

C:\>tlib maths.lib + c:\sqr.obj

Please note the paths. Your paths may be different than mine!

here, maths.lib is the library and + is a switch which indicates that we want to add a new function to the library and the object file is at the given path.

Header file:

Add the prototype of square() function in a header file (lets say “square.h”) This file should be included in the program where we want to use the function. we can use it as:

#include “c:\square.h”

Thats all !

Use the function and enjoy !!

Hope it helps.

Inheritance and Mixins

Some object-oriented languages (such as C++) support multiple inheritance, where a class can have more than one immediate parent,
inheriting functionality from each. Although powerful, this technique can be dangerous, because the inheritance hierarchy can become
ambiguous.
Other languages, such as Java and C#, support single inheritance. Here, a class can have only one immediate parent. Although cleaner
(and easier to implement), single inheritance also has drawbacks—in the real world objects often inherit attributes from multiple sources (a
ball is both a bouncing thing and a spherical thing, for example).

Ruby offers an interesting and powerful compromise, giving you the simplicity of single inheritance and the power of multiple inheritance. A
Ruby class has only one direct parent, so Ruby is a single-inheritance language. However, Ruby classes can include the functionality of
any number of mixins (a mixin is like a partial class definition). This provides a controlled multiple-inheritance-like capability with none of
the drawbacks.