Found 34494 Articles for Programming

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

Union in C

karthikeya Boyini
Updated on 26-Jun-2020 08:04:15

556 Views

Union is a user defined datatype. All the members of union share same memory location. Size of union is decided by the size of largest member of union. If you want to use same memory location for two or more members, union is the best for that.Unions are similar to the structure. Union variables are created in same manner as structure variables. The keyword “union” is used to define unions in C language.Here is the syntax of unions in C language, union union_name {    member definition; } union_variables;Here, union_name − Any name given to the union.member definition − Set ... Read More

Structures in C

Samual Sam
Updated on 26-Jun-2020 07:50:01

832 Views

Structure is a user defined datatype. It is used to combine the different types of data into single type. It can have multiple members and structure variables. The keyword “struct” is used to define structures in C language. Structure members can be accessed by using dot(.) operator.Here is the syntax of structures in C language, struct structure_name {    member definition; } structure_variables;Here, structure_name − Any name given to the structure.member definition − Set of member variables.structure_variable − This is the object of structure.Here is an example of structures in C language, Example Live Demo#include #include struct Data { ... Read More

Advertisements