Found 1401 Articles for C

How to clear console in C?

Samual Sam
Updated on 26-Jun-2020 08:18:37

19K+ Views

There are several methods to clear the console or output screen and one of them is clrscr() function. It clears the screen as function invokes. It is declared in “conio.h” header file. There are some other methods too like system(“cls”) and system(“clear”) and these are declared in “stdlib.h” header file.Here is the syntax to clear the console in C language, clrscr(); OR system(“cls”); OR system(“clear”);Here is an example to clear the console in C language, Let’s say we have “new.txt” file with the following content −0, hell!o 1, hello! 2, gfdtrhtrhrt 3, demoNow, let us see the example.Example#include #include void ... Read More

mbrlen() function in C/C++

karthikeya Boyini
Updated on 26-Jun-2020 08:19:06

134 Views

The function mbrlen() is used to get the length of multibyte character. It returns the size of multibyte character pointed by the pointer.Here is the syntax of mbrlen() in C language, size_t mbrlen(const char* pointer, size_t size, mbstate_t* state);Here, pointer − Pointer to the first byte of multibyte character.size − Number of bytes to check.state − Pointer to the object of mbstate_tHere is an example of mbrlen() in C language, Example Live Demo#include #include #include int main(void) {    char a[] = "s";    mbstate_t s;    int len;    len = mbrlen(a, 5, &s);    printf("Length of ... Read More

raise() function in C/C++

Samual Sam
Updated on 26-Jun-2020 08:05:21

305 Views

The function raise() is used to send the signals to the program. The predefined function signal() is invoked. It is implemented to check whether it will ignore the signal or invoke the signal handler. This is declared in “signal.h” header file. It returns zero, if successful otherwise, non-zero value.Here is the syntax of raise() in C language, int raise(int signal)Here, signal − The signal number to be invoked.Here is an example of raise() in C language, Example Live Demo#include #include void handler(int sig) {    printf("Signal received : %d", sig); } int main() {    signal(SIGILL, handler);    printf("Sending ... Read More

atexit() function in C/C++

karthikeya Boyini
Updated on 26-Jun-2020 08:05:54

310 Views

The function atexit() is used to call the function after the normal exit of program. The program is called without any parameters. The function atexit() is called after exit(). The termination function can be called anywhere in the program. This function is declared in “stdlib.h” header file.Here is the syntax of atexit() in C language, int atexit(void (*function_name)(void))Here, function_name − The function is to be called at the time of termination of program.Here is an example of atexit() in C language, Example Live Demo#include #include void func1 (void) {    printf("Exit of function 1"); } void func2 (void) { ... Read More

ungetc() in C/C++

Samual Sam
Updated on 26-Jun-2020 08:06:26

181 Views

The function ungetc() takes a character and pushes it back to the stream so that the character could be read again.Here is the syntax of ungetc() in C language, int ungetc(int character, FILE *stream)Here, character − The character to be pushed back to stream.stream − The pointer to the file object.Here is an example of ungetc() in C language, Example#include int main() {    int c;    while ((c = getchar()) != '0')    putchar(c);    ungetc(c, stdin);    c = getchar();    putchar(c);    puts("");    printf("The End!");    return 0; }Outputs a b c t h 0 ... Read More

Difference between strlen() and sizeof() for string in C

karthikeya Boyini
Updated on 26-Jun-2020 08:07:54

785 Views

strlen()The function strlen() is a predefined function in C language. This is declared in “string.h” header file. It is used to get the length of array or string.Here is the syntax of strlen() in C language, size_t strlen(const char *string);Here, string − The string whose length is to be calculated.Here is an example of strlen() in C language, Example Live Demo#include #include int main () {    char s1[10] = "Hello";    int len ;    len = strlen(s1);    printf("Length of string s1 : %d", len );    return 0; }OutputLength of string s1 : 10In the above ... Read More

memcpy() function in C/C++

Samual Sam
Updated on 26-Jun-2020 08:08:37

5K+ Views

The function memcpy() is used to copy a memory block from one location to another. One is source and another is destination pointed by the pointer. This is declared in “string.h” header file in C language. It does not check overflow.Here is the syntax of memcpy() in C language, void *memcpy(void *dest_str, const void *src_str, size_t number)Here, dest_str − Pointer to the destination array.src_str − Pointer to the source array.number − The number of bytes to be copied from source to destination.Here is an example of memcpy() in C language, Example Live Demo#include #include int main () {   ... Read More

memmove() function in C/C++

karthikeya Boyini
Updated on 26-Jun-2020 08:09:03

373 Views

The function memmove() is used to move the whole memory block from one position to another. One is source and another is destination pointed by the pointer. This is declared in “string.h” header file in C language.Here is the syntax of memmove() in C language, void *memmove(void *dest_str, const void *src_str, size_t number)Here, dest_str − Pointer to the destination array.src_str − Pointer to the source array.number − The number of bytes to be copied from source to destination.Here is an example of memmove() in C language, Example Live Demo#include #include int main () {    char a[] = "Firststring"; ... Read More

How can I convert string to double in C/C++?

Samual Sam
Updated on 26-Jun-2020 08:09:32

819 Views

Here is an example to convert a string to double.Example Live Demo#include using namespace std; int main() {    char s[20] = "18.2894 is a number";    char *p;    double result;    result = strtod(s, &p);    cout

strtod() function in C/C++

karthikeya Boyini
Updated on 26-Jun-2020 08:10:10

314 Views

The function strtod() is used to convert the string to a floating point number. The string is converted into double type number. It returns the converted number, if successful otherwise, zero. This is declared in “stdlib.h” header file.Here is the syntax of strtod() in C language, double strtod(const char *string, char **endpointer);Here, string − The string to be converted.endpointer − The pointer of already allocated object and its value is set to the next character by the function after the numeric value.Here is an example of strtod() in C language, Example Live Demo#include #include int main () {   ... Read More

Advertisements