Tag Archives: C strings

substr string function csubstr in c

csubstr string function in c

To get substring from string:

Function prototype:

char *csubstr(char *str,int sp,int noc);

where sp is starting point of substring and noc is number of characters to be taken

csubstr function implementation in c.

substr string function in c

cstrcmp string function in c

cstrcmp string function in c

To compare two strings cstrcmp() :

Function prototype:

int cstrcmp(char *strn1,char *strn2);

cstrcmp function takes two string strn1 and strn2 as input and then returns 1 if both strings are same else returns 0;

cstrcmp string function  implementation in c :


cstrcmp string function in c

C Chars & ascii

Characters are used to store literal values, like names of person , names of items etc..  Array of character is known as strings. Strings are terminated by null (‘’) character.

Single char variable takes 1 byte. so if we declare char array of 10 size it will take 10 bytes.

Declaration :

Above declaration will consume 1 byte of memory.

above declaration will consume 10 byte of memory

Initialization at the time of declaration:

Character arithmetic :

In c every characters has its ascii values.The below chart shows ascii value and character. There are 128 ascii values in C.

Functions supported by chars and strings :

Some function are listed below used to manipulate string and chars.

Function Name Description
getc() Used to input char from stdin
putc() Used to print char on  stdout (screen)
Gets() Used to input string from stdin
Puts() Used to print string on  stdout (screen)
Strcpy() Used to copy one string into other string variable
Strcat() Used to join two strings
Strchr() To find position of char in string
Strlen() To find length of string