Checking whether string is empty or not
In this, we are going see a program on string manipulation to check whether string is empty or not in C++ Programming Language.



The Code given below can be used in TURBO C++ Compilers: -

#include <iostream.h>
#include <string.h>
#include <conio.h>

void main()
{
    clrscr();
    char a[50] = "Abhishek";
    char b[50];
    strcpy(b,a);
    cout<<b;
    int c = strlen(b);
    if(c>0)
    {
	cout<<"String is not empty";
    }
    else
    cout<<"String is empty";
    getch();
}

//........Coded by YASH ALAPURIA

The Code given below can be used in gcc/g++ Compilers: -

#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;

int main()
{
    system("cls");
    string str1 = "Help for coders.";
    string str2;

    if (str1.empty())
        cout<<"String is empty";

    else
        cout<<"String is not empty";


    if (str2.empty())
        cout<<"\nString is empty";

    else
        cout<<"\nString is not empty";
    
    return 0;
}

//........Coded by YASH ALAPURIA

#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post