Found 1401 Articles for C

isupper() function in C Language

Samual Sam
Updated on 26-Jun-2020 08:10:38

2K+ Views

The function isupper() is used to check that the character is uppercase or not. It returns non-zero value if successful otherwise, return zero. It is declared in “ctype.h” header file.Here is the syntax of isupper() in C language, int isupper(int character);Here, character − The character which is to be checked.Here is an example of isupper() in C language, Example Live Demo#include #include int main() {    char val1 = 's';    char val2 = 'S';    if(isupper(val1))    printf("The character is uppercase");    else    printf("The character is not uppercase");    if(isupper(val2))    printf("The character is uppercase");    else    printf("The ... Read More

isalnum() function in C Language

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

8K+ Views

The function isalnum() is used to check that the character is alphanumeric or not. It returns non-zero value, if the character is alphanumeric means letter or number otherwise, returns zero. It is declared in “ctype.h” header file.Here is the syntax of isalnum() in C language, int isalnum(int character);Here, character − The character which is to be checked.Here is an example of isalnum() in C language, Example Live Demo#include #include int main() {    char val1 = 's';    char val2 = '8';    char val3 = '$';    if(isalnum(val1))    printf("The character is alphanumeric");    else    printf("The character is not ... Read More

Print contents of a file in C

Samual Sam
Updated on 26-Jun-2020 07:56:43

6K+ Views

Here is an example to print contents of a file 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 main() {    FILE *f;    char s;    clrscr();    f=fopen("new.txt", "r");    while((s=fgetc(f))!=EOF) {       printf("%c", s);    }    fclose(f);    getch(); }Output0, hell!o 1, hello! 2, gfdtrhtrhrt 3, demoIn the above program, we have a text file “new.txt”. A file pointer is used to open and read the file. It is displaying the content of file.FILE *f; ... Read More

fopen() for an existing file in write mode in C

karthikeya Boyini
Updated on 26-Jun-2020 07:57:29

525 Views

The function fopen() opens the file pointed by pointer and read or write the file. In the write mode, “w” is used and in the read mode, “r” is used.When a file exists in the directory, it treats as a new empty file and override the content of file by new data.Here is the syntax of fopen() in C langauge, FILE *fopen(const char *filename, const char *access_mode)Here, filename − The name of file which is to be opened.acess_mode − The mode to access the file like read or write mode.Here is an example of fopen() in C language, Let’s say ... Read More

Use of realloc() in C

Samual Sam
Updated on 26-Jun-2020 07:58:12

11K+ Views

The function realloc is used to resize the memory block which is allocated by malloc or calloc before.Here is the syntax of realloc in C language, void *realloc(void *pointer, size_t size)Here, pointer − The pointer which is pointing the previously allocated memory block by malloc or calloc.size − The new size of memory block.Here is an example of realloc() in C language, Example Live Demo#include #include int main() {    int n = 4, i, *p, s = 0;    p = (int*) calloc(n, sizeof(int));    if(p == NULL) {       printf("Error! memory not allocated.");     ... Read More

EOF, getc() and feof() in C

karthikeya Boyini
Updated on 14-Sep-2023 20:45:57

24K+ Views

EOFEOF stands for End of File. The function getc() returns EOF, on success..Here is an example of EOF in C language, Let’s say we have "new.txt" file with the following content.This is demo! This is demo!Now, let us see the example.Example#include int main() {    FILE *f = fopen("new.txt", "r");    int c = getc(f);    while (c != EOF) {       putchar(c);       c = getc(f);    }    fclose(f);    getchar();    return 0; }OutputThis is demo! This is demo!In the above program, file is opened by using fopen(). When integer variable c ... Read More

fseek() vs rewind() in C

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

2K+ Views

fseek()fseek() in C language is used to move file pointer to a specific position. Offset and stream are the destination of pointer, given in the function parameters. If successful, it returns zero, else non-zero value is returned.Here is the syntax of fseek() in C language, int fseek(FILE *stream, long int offset, int whence)Here are the parameters used in fseek(), stream − This is the pointer to identify the stream.offset − This is the number of bytes from the position.whence − This is the position from where offset is added.whence is specified by one of the following constants.SEEK_END − End of ... Read More

calloc() versus malloc() in C

karthikeya Boyini
Updated on 26-Jun-2020 08:01:39

2K+ Views

calloc()The function calloc() stands for contiguous location. It works similar to the malloc() but it allocate the multiple blocks of memory each of same size.Here is the syntax of calloc() in C language, void *calloc(size_t number, size_t size);Here, number − The number of elements of array to be allocated.size − Size of allocated memory in bytes.Here is an example of calloc() in C language, Example Live Demo#include #include int main() {    int n = 4, i, *p, s = 0;    p = (int*) calloc(n, sizeof(int));    if(p == NULL) {       printf("Error! memory not allocated."); ... Read More

fgetc() and fputc() in C

Samual Sam
Updated on 26-Jun-2020 08:02:42

4K+ Views

fgetc()The function fgetc() is used to read the character from the file. It returns the character pointed by file pointer, if successful otherwise, returns EOF.Here is the syntax of fgetc() in C language, int fgetc(FILE *stream)Here is an example of fgetc() 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 main() {    FILE *f;    char s;    clrscr();    f=fopen("new.txt", "r");    while((s=fgetc(f))!=EOF) {       printf("%c", s);    }    fclose(f);    getch(); }Here is the ... Read More

isgreaterequal() in C/C++

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

154 Views

The function isgreaterequal() is used to check that the first argument is greater than or equal to the second one. It is declared in “math.h” header file in C language. It returns true on success, otherwise false.Here is the syntax of islessgreater() in C++ language, bool isgreaterequal(value1 , value2);Here, value1 − This is the first argument which will be checked with value2.value2 − This is the second argument which is used to check value1 that is greater or equal.Here is an example of isgreaterequal() in C++ language, Example Live Demo#include #include using namespace std; int main() {    int val1 = ... Read More

Advertisements