Posts

String function i.e. Search, Equal ,Smaller, Greater,Getsub,LeftSub,Rightsub , Upper, Lower ,Reverse,Replace

#include #include #include #include String function i.e. Search, Equal ,Smaller, Greater,Getsub,LeftSub,Rightsub , Upper, Lower ,Reverse,Replace type function int search ( char *, char ) ; int isequals ( char *, char * ) ; int issmaller ( char *, char * ) ; int isgreater ( char *, char * ) ; char * getsub ( char *, int, int ) ; char * leftsub ( char *, int n ) ; char * rightsub ( char *, int n ) ; void upper ( char * ) ; void lower ( char * ) ; void reverse ( char * ) ; int replace ( char *, char, char ) ; int setat ( char *, char, int ) ; void main( ) { char s1[ ] = "Hello" ; char s2[ ] = "Hello World" ; char s3[ ] = "Four hundred thirty two" ; char ch, *s ; int i ; clrscr( ) ; printf ( "\nString s1: %s", s1 ) ; /* check for the first occurrence of a character */ printf ( "\nEnter character to search: " ) ; scanf ( "%c", &ch ) ; i = search ( s1, ch ) ; if ( i != -1 ) printf ( "The first occurrence of c...

Program to search for a string into another string.

/* Program to search for a string into another string. */ #include #include #include int xstrsearch ( char *, char * ) ; void show( ) ; void main( ) { char s1[ ] = "NagpurKicit" ; char s2[ ] = "Kicit" ; int pos ; clrscr( ) ; printf ( "String s1: %s\n", s1 ) ; printf ( "String s2: %s\n", s2 ) ; /* search if s2 is present in s1 */ pos = xstrsearch ( s1, s2 ) ; printf ( "\nThe pattern string is found at position: %d\n", pos ) ; getch( ) ; } /* searches for the given pattern s2 into the string s1 */ int xstrsearch ( char * s1, char * s2 ) { int i, j, k ; int l1 = strlen ( s1 ) ; int l2 = strlen ( s2 ) ; for ( i = 0 ; i { j = 0 ; k = i ; while ( ( s1[k] == s2[j] ) && ( j { k++ ; j++ ; } if ( j == l2 ) return i ; } return -1 ; }

Program to allocate memory dynamically for strings, and store their addresses in array of pointers to strings

/* Program to allocate memory dynamically for strings, and store their addresses in array of pointers to strings. */ #include #include #include #include void main( ) { char *name[5] ; char str[20] ; int i ; clrscr( ) ; for ( i = 0 ; i { printf ( "Enter a String: " ) ; gets ( str ) ; name[i] = ( char * ) malloc ( strlen ( str ) + 1 ) ; strcpy ( name[i], str ) ; } printf ( "\nThe strings are:" ) ; for ( i = 0 ; i printf ( "\n%s", name[i] ) ; for ( i = 0 ; i free ( name[i] ) ; getch( ) ; }

Program to check entered name in the master list.

/* Program to check entered name in the master list. */ #include #include #include #define MAX1 6 #define MAX2 10 char masterlist[MAX1][MAX2] ; int count ; int add ( char *s ) ; int find ( char *s ) ; void main( ) { char yourname[MAX2] ; int flag ; clrscr( ) ; flag = add ( "akshay" ) ; if ( flag == 0 ) printf ( "\nUnable to add string" ) ; flag = add ( "parag" ) ; if ( flag == 0 ) printf ( "\nUnable to add string" ) ; flag = add ( "raman" ) ; if ( flag == 0 ) printf ( "\nUnable to add string" ) ; flag = add ( "srinivas" ) ; if ( flag == 0 ) printf ( "\nUnable to add string" ) ; flag = add ( "gopal" ) ; if ( flag == 0 ) printf ( "\nUnable to add string" ) ; flag = add ( "rajesh" ) ; if ( flag == 0 ) printf ( "Unable to add string" ) ; printf ( "Enter your name: " ) ; gets ( yourname ) ; flag = find ( yourname ) ; if ( flag == 1...

Program to perform some basic operations on string.

/* Program to perform some basic operations on string. */ #include #include #include int xstrlen ( char * ) ; void xstrcpy ( char *, char * ) ; void xstrcat ( char *, char * ) ; int xstrcmp ( char *, char * ) ; void show ( char * ) ; void main( ) { char s1[ ] = "kicit" ; char s2[ ] = "Nagpur" ; char s3[20] ; int len ; clrscr( ) ; printf ( "\nString s1: %s", s1 ) ; len = xstrlen ( s1 ) ; printf ( "\nlength of the string s1: %d", len ) ; printf ( "\nString s2: %s", s2 ) ; xstrcpy ( s3, s1 ) ; printf ( "\nString s3 after copying s1 to it: %s", s3 ) ; xstrcat ( s3, s2 ) ; printf ( "\nString s3 after concatenation: %s", s3 ) ; if ( xstrcmp ( s1, s2 ) == 0 ) printf ( "\nThe strings s1 and s2 are similar" ) ; else printf ( "\nThe strings s1 and s2 are not similar" ) ; getch( ) ; } /* finds the length of the string */ int xst...

Program for matrix operations like dertminant, singular, etc.

#include #include #include #define MAX 3 void matrix ( int [3][3] ) ; void create ( int [3][3] ) ; void display ( int [3][3] ) ; void matmul ( int [3][3], int [3][3], int [3][3] ) ; void transpose ( int [3][3], int [3][3] ) ; int determinant ( int [3][3] ) ; int isortho ( int [3][3] ) ; void main( ) { int mat [3][3], d ; clrscr( ) ; printf ( "\nEnter elements for array: \n\n" ) ; create ( mat ) ; printf ( "\nThe Matrix: \n" ) ; display ( mat ) ; d = determinant ( mat ) ; printf ( "\nThe determinant for given matrix: %d.\n", d ) ; if ( d == 0 ) printf ( "\nMatrix is singular.\n" ) ; else printf ( "\nMatrix is not singular.\n" ) ; d = isortho ( mat ) ; if ( d != 0 ) printf ( "\nMatrix is orthogonal.\n" ) ; else printf ( "\nMatrix is not orthogonal.\n" ) ; getch( ) ; } /* initializes the matrix mat with 0 */ void matrix ( int mat[3]...

Advance Concept of Data Structure

/*: Program to implement an array. with data structure */ #include #include #define MAX 5 void insert ( int *, int pos, int num ) ; void del ( int *, int pos ) ; void reverse ( int * ) ; void display ( int * ) ; void search ( int *, int num ) ; void main( ) { int arr[5] ; clrscr( ) ; insert ( arr, 1, 11 ) ; insert ( arr, 2, 12 ) ; insert ( arr, 3, 13 ) ; insert ( arr, 4, 14 ) ; insert ( arr, 5, 15 ) ; printf ( "\nElements of Array: " ) ; display ( arr ) ; del ( arr, 5 ) ; del ( arr, 2 ) ; printf ( "\n\nAfter deletion: " ) ; display ( arr ) ; insert ( arr, 2, 222 ) ; insert ( arr, 5, 555 ) ; printf ( "\n\nAfter insertion: " ) ; display ( arr ) ; reverse ( arr ) ; printf ( "\n\nAfter reversing: " ) ; display ( arr ) ; search ( arr, 222 ) ; search ( arr, 666 ) ; getch( ) ; } /* inserts an element num at given position pos */ void insert ( int *arr, int pos, i...