Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C Articles - Page 127 of 134
957 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
6K+ 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
616 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
1K+ Views
Given a string like "-27.89", we can convert it into a double value such as -27.890000. In this article, we use various approaches from C/C++ library functions to perform this string into double conversion: Using atof() Function Using strtod() Function Using stod() Function Using stringstream() Function String to Double Conversion Using atof() Function You can use atof() function of C library that accepts the parameter of string value to convert the string into a double. Example In this example, we illustrate atof() to convert string into double. #include #include int main() { ... Read More
420 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
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
9K+ 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
7K+ 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
724 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
12K+ 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