×

C String Manipulation programs without using Library Functions

C string manipulation programs without using Library Functions

The string is the character list, and typically we operate with library functions to read and print the entire string, but here you can find a compilation of solved c example based on string manipulation. We can perform with strings and render most programs without using string.h in the header file.

We are going to get and manipulate will character from the character list, and use our specific technic to display the string.

List of solved string manipulation programs

C program to individually print all of the VOWEL and CONSONANT characters.

During this program, we will individually print all VOWEL and CONSONANT characters from an obtained string, the logic behind whilst implementing the entire program too effectively, you just have to check if those characters are vowels to print them out like vowels and not to print them as consonants.

#include<stdio.h>
int main()
{
    character text[100];
    int j;
    printf("Please enter any string character: ");
    gets(text);
    printf("Your String character is: ");
    for(j=0;text[j]!='\0';j++)
    {
        printf("%c",text[j]);
    }
    printf("\n");
    printf("VOWEL Characters is: ");
    for(j=0;text[j]!='\0';j++)
    {
        if(text[j]=='A' || text[j]=='a' || text[j]=='E' || text[j]=='e' || text[j]=='I' || text[j]=='j' || text[j]=='O' || text[j]=='o' || text[j]=='U' || text[j]=='u')
            printf("%c",text[j]);
    }
    printf("\n");
    printf("CONSONANT Characters is: ");
    for(j=0;text[j]!='\0';j++)
    {
        if(!(text[j]=='A' || text[j]=='a' || text[j]=='E' || text[j]=='e' || text[j]=='I' || text[j]=='j' || text[j]=='O' || text[j]=='o' || text[j]=='U' || text[j]=='u'))
            printf("%c",text[j]);
    }
    printf("\n");
    return 0;
}

Output:

C string manipulation programs without using Library Functions

C program to use a loop to print string one by one character.

As we notice, a string may be displayed through printf("percent s, "string variable), but in this approach, we will print string one by one character using a loop. Here the loop runs from 0 to Null.

#include<stdio.h>
int main()
{
    character text[100];
    int j;
    printf("Please enter any string character: ");
    gets(text);
    printf("Your String character is: ");
    for(j=0;text[j]!='\0';j++)
    {
        printf("%c",text[j]);
    }
    printf("\n");
    return 0;
}

Output:

C string manipulation programs without using Library Functions

C program to count a string of upper case, lower case, and special characters.

We'll be counting upper case, lower case, and special characters in this program. The logic behind implementing this system is too simple, if it is alphabet search for lower and upper case characters, if characters are not alphabets count them as special characters, just test characters is alphabet or no.

/*C program to count upper case, lower case and special characters in a string.*/
#include<stdio.h>
int main()
{
    char text[100];
    int j;
    int countLow,countUpp,countSpe;
    printf("Enter any string: ");
    gets(text);
    //here, we are printing string using printf
    //without using loop
    printf("Entered string is: %s\n",text);
    //count lower case, upper case and special characters
    //assign 0 to counter variables
    countLow=countUpp=countSpe=0;
    for(j=0;text[j]!='\0';j++)
    {
        //check for alphabet
        if((text[j]>='A' && text[j]<='Z') || (text[j]>='a' && text[j]<='z'))
        {
            if((text[j]>='A' && text[j]<='Z'))
            {
                //it is upper case alphabet
                countUpp++;
            }
            else
            {
                //it is lower case character
                countLow++;
            }
        }
        else
        {
            //character is not an alphabet
            countSpe++; //it is special character
        }
    }
    //print values
    printf("Upper case characters: %d\n",countUpp);
    printf("Lower case characters: %d\n",countLow);
    printf("Special characters: %d\n",countSpe);
    return 0;
}

Output:

C string manipulation programs without using Library Functions

C program to toggle the case of all string characters.

Therefore in the program, we will toggle the case of string for all characters. The logic behind such a program is to convert the character of the lowercase letter in the uppercase letters and the upper case character in the lowercase letters, but the first test whether the letter is an alphabet or not, if this is alphabet then just do it.

#include<stdio.h>
int main()
{
    character text[100];
    int k;
    printf("Please enter any string character: ");
    gets(text);
    printf("Your String character is: %s\n",text);
    for(k=0;text[k]!='\0';k++)
    {
        //check character is alphabet or not
        if((text[k]>='A' && text[k]<='Z')||(text[k]>='a' && text[k]<='z'))
        {
            //check for upper case character
            if(text[k]>='A' && text[k]<='Z')
                text[k]=text[k]+0x20;
            else
                text[k]=text[k]-0x20;
        }
    }
    printf("String after toggle case: %s\n",text);
    return 0;
}

Output:

C string manipulation programs without using Library Functions

Related Topics

Selection sort in C

In the C standard, the selection sorting technique exists where the smallest among the unsorted elements of the array is selected at each time and is then inserted into its...

3 minutes read.

strtok() and strtok_r() functions in C with examples

strtok() and strtok_r() functions in C with examples C offer various strtok() and strtok r() methods for a string to be separated by a certain delimiter. Dividing a string is a...

2 minutes read.

Difference between Pre-increment and Post-increment in C

Increment operators are the kind of operators that are used to increment the cost of the operand by way of 1. In different words, the increment operator is an operator...

4 minutes read.

DSA Program in C

How is a Data Structure Implemented? The foundational terms of a data structure are the following terms. Data may be arranged using data structures to make it easier to use. Each data...

20 minutes read.

Big O Notation in C

Big O Notation in C: In the C programming language, we have so many algorithms and solutions to the problems that exist, which have different aspects and purposes to an...

3 minutes read.

For loop in C Programming

In the C programming language, the for loop is used to repeatedly iterate over a set of instructions or a section of code. It is frequently used to traverse array-based...

3 minutes read.

Conio.h in C

Header files are the source files with the extension of .h. In c language header files are referred to as the helping files and they contain definitions of various functions...

4 minutes read.

Runtime vs compile time in C

In the C programming language, the often used terms in every step consist of compile time and runtime. The compile time is referred to the source code that will be...

4 minutes read.

Continue in C

C language: C language is a procedure oriented programming language. We can say that it is a platform dependent language. C language is introduced by Dennis Ritchie in the year 1970. We...

2 minutes read.

Add two numbers using the function in C

Here we will learn how to add two numbers by creating function in C. Let’s learn this with help of example. Code: - #include <stdio.h> int add_two_no(int a, int b); int main(){   int first_num,...

1 minute read.

Difference between Scope and Lifetime in C

In this article, we will discuss about the key differences between scope and lifetime in C, including their definitions, applications, and how they relate to one another. By the end...

8 minutes read.

Bubble sort in C

Bubble sort in C Bubble sort is defined as the algorithm that is used for the sorting mechanism. It follows the technique of replacing the first index with the more minor...

4 minutes read.

Classification of Programming language

 Classification of Programming language  The programming language represents a set of instructions compiled along with each other to perform a specific task provided by the CPU (Central Processing Unit). A programming...

3 minutes read.

Loop Statement in C

Loop statement is used to execute one or more statement repeatedly multiple times. There are three types of loops in C language. Why use loop? We can use loop because it executes a...

2 minutes read.

Difference between while and for loop in C

While Loop The syntax that can be used for the ‘while’ loop in the C programming language is mentioned below: while (test expression or termination condition)  {   // the main body of the...

6 minutes read.

Fahrenheit to Celsius in C

Before going into conversion, we have to know what Fahrenheit and Celsius mean, these are both units to measure the temperature.In our daily life, we use both Fahrenheit and Celsius,...

1 minute read.

Fibonacci series in C

We have learned about the Fibonacci series in mathematics. For a quick recap, A Fibonacci series is the sequence of numbers following a certain pattern i.e., the next number should...

3 minutes read.

Functions in C

What is function? Functions are defined as the set of announcements which take inputs, perform operations and provide results. The operation of a function only performs when the function gets called....

4 minutes read.

Isalnum() function in C

Introduction: The isalnum () is a function used in C programming language. This function checks the passing number or argument is an alphanumeric number or not. The alphanumeric number consists of the...

3 minutes read.

Multilevel Feedback Queue Scheduling (MLFQ) CPU Scheduling

In this article, you will learn how to initialise an array to 0 in C In C, an array is declared as: char ZEROARRAY[2022]; The global scope changes at runtime to all zeros....

3 minutes read.