Category Archives: c string

Check whether string can be generated from given grammar ?

Write a code to check whether given string can be generated from given grammar ?

Grammar  :

S – > 122S
S – > 12S
S – > 1S
S – > “”

==================================================================================
Input :
12221
Output :
0

===================================================================================

Input :
121
Output:
1

====================================================================================

O = > False (Cannot be generated)

1 = > True (Can be generated)

 

 

 

C code to hide input password

C program to hide input password with *
In this code Password accepts all character except ‘\n’ .

password

 

 

 

C code to implement myatoi function

 

implementation of myatoi function in c.

Atoi function converts a string numeric value into integer value.

 

 

C code to reverse words in place in a string

C program to reverse words in place in a string:

Approach :

Step1: Reverse the whole string

Step2: Reverse the characters in words

e.g.

Before Rev Old: [I am a good coder]

After Rev: [redoc doog a ma I]

New: [coder good a am I]

 

 

 

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

string copy function cstrncpy in c

cstrncpy string copy function in c

To copy one string into another string cstrncpy() :

Function prototype:

int cstrcpy(char *dst,char *src);

cstrncpy function takes two string dst and str as input copies the data from src to dst and then returns 1 if both string is copied else returns zero id src is null;

cstrncpy string copy function  implementation 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

Implementation of string length function in c

string length function in C, to calculate a length of string ( cstrlen() )  :

Function prototype :

int cstrlen(char *str);

cstrlen function takes a string as an argument and returns number of character in that string ;

cstrlen  string length function implementation in c

c strlen implementation in c , String length function in c