Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


C Programming Code Examples

C > Strings Code Examples

Remove all Characters in Second String which are present in First String

/* Remove all Characters in Second String which are present in First String */ #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> #define CHAR_SIZE 26 void alphacheck(char *, int []); void create(char [], char [], int[]); int main() { char str1[50], str2[50]; int a1[CHAR_SIZE] = {0}; char str2_rem[50]; printf("Enter string1: "); scanf("%s", str1); printf("Enter string2: "); scanf("%s", str2); alphacheck(str1, a1); create(str2_rem, str2, a1); printf("On removing characters from second string we get: %s\n", str2_rem); return 0; } void alphacheck(char *str, int a[]) { int x, index; for (x = 0; x < strlen(str); x++) { str[x] = tolower(str[x]); index = str[x] - 'a'; if (!a[index]) { a[index] = 1; } } printf("\n"); } void create(char str_rem[], char str[], int list[]) { int x, j = 0, index; for (x = 0; x < strlen(str); x++) { index = str[x] - 'a'; if (!list[index]) { str_rem[j++] = str[x]; } } str_rem[j] = '\0'; }

Convert uppercase letter to lowercase. Converts c to its lowercase equivalent if c is an uppercase letter and has a lowercase equivalent. If no such conversion is possible, the value returned is c unchanged. Notice that what is considered a letter may depend on the locale being used; In the default "C" locale, an uppercase letter is any of: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z, which translate respectively to: a b c d e f g h i j k l m n o p q r s t u v w x y z.

In the C Programming Language, the #define directive allows the definition of macros within your source code. These macro definitions allow constant values to be declared for use throughout your code. Macro definitions are not variables and cannot be changed by your program code like variables. You generally use this syntax when creating constants that represent numbers, strings or expressions.

The for loop is used in the case where we need to execute some part of the code until the given condition is satisfied. The for loop is also called as a per-tested loop. It is better to use for loop if the number of iteration is known in advance. The for-loop statement is a very specialized while loop, which increases the readability of a program. It is frequently used to traverse the data structures like the array and linked list.

The if-else statement is used to perform two operations for a single condition. The if-else statement is an extension to the if statement using which, we can perform two different operations, i.e., one is for the correctness of that condition, and the other is for the incorrectness of the condition. Here, we must notice that if and else block cannot be executed simiulteneously. Using if-else statement is always preferable since it always invokes an otherwise case with every if condition.

Get string length. Returns the length of the C string str. The length of a C string is determined by the terminating null-character: A C string is as long as the number of characters between the beginning of the string and the terminating null character (without including the terminating null character itself).

Writes the C string pointed by format to the standard output (stdout). If format includes format specifiers (subsequences beginning with %), the additional arguments following format are formatted and inserted in the resulting string replacing their respective specifiers. printf format string refers to a control parameter used by a class of functions in the input/output libraries of C programming language. The string is written in a simple template language: characters are usually copied literally into the function's output, but format specifiers, which start with a % character, indicate the location and method to translate a piece of data (such as a number) to characters. "printf" is the name of one of the main C output functions, and stands for "print formatted". printf format strings are complementary to scanf format strings, which provide formatted input (parsing). In both cases these provide simple functionality and fixed format compared to more sophisticated and flexible template engines or parsers,

In C, the "main" function is treated the same as every function, it has a return type (and in some cases accepts inputs via parameters). The only difference is that the main function is "called" by the operating system when the user runs the program. Thus the main function is always the first code executed when a program starts. main() function is a user defined, body of the function is defined by the programmer or we can say main() is programmer/user implemented function, whose prototype is predefined in the compiler. Hence we can say that main() in c programming is user defined as well as predefined because it's prototype is predefined. main() is a system (compiler) declared function whose defined by the user, which is invoked automatically by the operating system when program is being executed.

An expression containing logical operator returns either 0 or 1 depending upon whether expression results true or false. Logical operators are commonly used in decision making in C programming. These operators are used to perform logical operations and used with conditional statements like C if-else statements.

#include is a way of including a standard or user-defined file in the program and is mostly written at the beginning of any C/C++ program. This directive is read by the preprocessor and orders it to insert the content of a user-defined or system header file into the following program. These files are mainly imported from an outside source into the current program. The process of importing such files that might be system-defined or user-defined is known as File Inclusion. This type of preprocessor directive tells the compiler to include a file in the source code program. Here are the two types of file that can be included using #include:

Read formatted data from stdin. Reads data from stdin and stores them according to the parameter format into the locations pointed by the additional arguments. The additional arguments should point to already allocated objects of the type specified by their corresponding format specifier within the format string. In C programming, scanf() is one of the commonly used function to take input from the user. The scanf() function reads formatted input from the standard input such as keyboards. The scanf() function enables the programmer to accept formatted inputs to the application or production code. Moreover, by using this function, the users can provide dynamic input values to the application.




Pipe the output of program to the input of another. Duplicate stdin and stdout so we can restore them later. Make the write end of the pipe stdout. Run the program. Its output will


C Program implements 'Cyclesort'. Cycle sort is an in-place, unstable 'Sorting Algorithm', a comparison sort that is theoretically optimal in terms of the total number of writes to the

C language program code print to Equilateral Triangle. Triangle with all Sides Equal is called Equilateral Triangle. We shall now see how to print stars *, in Equilateral Triangle shape and



Function expression, array expression, unary minus, structure operators, increment and decrement, one's compliment, left and right shift, size of operator, pointer operators, type