Use Enums in C/C++

karthikeya Boyini
Updated on 24-Jun-2020 11:11:44

800 Views

Enumeration is a user defined datatype in C language. It is used to assign names to the integral constants, which makes a program easy to read and maintain. The keyword “enum” is used to declare an enumeration.Here is the syntax of enum in C language, enum enum_name{const1, const2, ....... };The enum keyword is also used to define the variables of enum type. There are two ways to define the variables of enum type as follows.enum week{sunday, monday, tuesday, wednesday, thursday, friday, saturday}; enum week day;Here is an example of enum in C language, Example#include enum week{Mon=10, Tue, Wed, Thur, Fri=10, ... Read More

iswlower Function in C/C++

karthikeya Boyini
Updated on 24-Jun-2020 11:10:43

229 Views

The function iswlower() is a built-in function in C/C++. It checks whether the wide character is in lower case or not. It is declared in “cwctype” header file in C++ language while “ctype.h” in C language. It takes a single character which is known as wide character. It will return zero(0), if the character is not a lower case character. It will return non-zero value, if character is lower case.Here is the syntax of iswlower() in C/C++ language, int iswlower(ch);Here is an example of iswlower() in C++ language, Example Live Demo#include #include using namespace std; int main() {   ... Read More

toupper Function in C/C++

Samual Sam
Updated on 24-Jun-2020 11:10:04

282 Views

The function iswupper() is a built-in function in C/C++. It converts the wide character into upper case. It is declared in “cwctype” header file in C++ language while “ctype.h” in C language. It takes a single character which is known as wide character. If the character is upper case, it is converted into it, otherwise no modifications happen.Here is the syntax of towupper() in C++ language, wint_t towupper( wint_t ch );Here is an example of towupper() in C++ language, Example#include #include #include using namespace std; int main() {    wchar_t s[] = L"hello world!";    wcout Read More

iswdigit Function in C/C++

karthikeya Boyini
Updated on 24-Jun-2020 11:09:44

245 Views

The function iswdigit() is a built-in function in C/C++. It checks whether the wide character is a decimal digit or not. It is declared in “cwctype” header file in C++ language while “ctype.h” in C language. It takes a single character which is known as wide character.The characters from 0 to 9 are classified as decimal digits. If the wide character is not a digit, it will return zero(0). If character is digit, it will return non-zero value.Here is the syntax of iswdigit() in C++ language, int iswdigit(ch)Here is an example of iswdigit() in C++ language, Example Live Demo#include #include ... Read More

Puts vs Printf for Printing a String in C Language

Samual Sam
Updated on 24-Jun-2020 11:09:13

3K+ Views

The function puts() and printf() are declared in stdio.h header file and are used to send the text to the output stream. Both have different usages and syntax.puts()The function puts() is used to print the string on the output stream with the additional new line character ‘’. It moves the cursor to the next line. Implementation of puts() is easier than printf().Here is the syntax of puts() in C language, puts(“string”);If you do not want the cursor to be moved to the new line, use the following syntax.fputs(string, stdout)Here is an example of puts() in C language, Example Live Demo#include int ... Read More

Use of \n in printf

karthikeya Boyini
Updated on 24-Jun-2020 11:08:45

4K+ Views

In C language, %n is a special format specifier. It cause printf() to load the variable pointed by corresponding argument. The loading is done with a value which is equal to the number of characters printed by printf() before the occurrence of %n.Note − It does not print anything. Another printf() function is used to print the statement.Here is an example of %n in C language, Example Live Demo#include int main() {    int s;    printf("The value of %ns : ", &s);    printf("%d", s);    getchar();    return 0; }OutputThe value of s : 13Even if we give the ... Read More

Print Output Using printf in C

Samual Sam
Updated on 24-Jun-2020 11:08:21

5K+ Views

Generally, printf() function is used to print the text along with the values. If you want to print % as a string or text, you will have to use ‘%%’. Neither single % will print anything nor it will show any error or warning.Here is an example to print % in printf() in C language, Example Live Demo#include int main() {    printf("%");    printf("%%");    getchar();    return 0; }Output%There are some other ways to print % in the text message as in the following example, Example Live Demo#include #include int main() {    printf("welcome%");    printf("%%");    printf("%c", '%');   ... Read More

printf, sprintf and fprintf in C

karthikeya Boyini
Updated on 24-Jun-2020 11:07:56

4K+ Views

printf()The function printf() is used to print the message along with the values of variables.Here is the syntax of printf() in C language, printf(const char *str, ...);Here is an example of printf() in C language, Example Live Demo#include int main() {    int a = 24;    printf("Welcome! ");    printf("The value of a : %d", a);    getchar();    return 0; }OutputWelcome! The value of a : 24sprintf()The function sprintf() is also known as string print function. It do not print the string. It stores the character stream on char buffer. It formats and stores the series of characters and ... Read More

Difference Between getc, getchar, getch, and getche

Samual Sam
Updated on 24-Jun-2020 11:07:13

6K+ Views

All these functions read the character from input and return an integer. The value of EOF is used for this purpose.getc()It reads a single character from the input and return an integer value. If it fails, it returns EOF.Here is the syntax of getc() in C language, int getc(FILE *stream);Here is an example of getc() in C language, Example Live Demo#include int main () {    char val;    printf("Enter the character: ");    val = getc(stdin);    printf("Character entered: ");    putc(val, stdout);    return(0); }OutputEnter the character: a Character entered: agetchar()The function getchar() reads the character from the standard ... Read More

strcpy in C and C++

karthikeya Boyini
Updated on 24-Jun-2020 11:06:39

4K+ Views

The function strcpy() is a standard library function. It is used to copy one string to another. In C language, it is declared in “string.h” header file while in C++ language, it is declared in cstring header file. It returns the pointer to the destination.Here is the syntax of strcpy() in C language, char* strcpy(char* dest, const char* src);Some key points of strcpy().It copies the whole string to the destination string. It replaces the whole string instead of appending it.It won’t change the source string.Here is an example of strcpy() in C language, Example Live Demo#include #include int main() { ... Read More

Advertisements