C Isdigit : Function Prototype of Isdigit
C Isdigit : Function Prototype of Isdigit
The isdigit() function checks whether a character is numeric character (0-9) or not.
Function isdigit() takes a single argument in the form of an integer and returns the
value of type int .
Even though, isdigit() takes integer as an argument, character is passed to the function.
Internally, the character is converted to its ASCII value for the check.
strcat() arguments
As you can see, the strcat() function takes two arguments:
destination - destination string
source - source string
The strcat() function concatenates the destination string and the source string, and
the result is stored in the destination string.
strrchr()
Description
The C library function char *strrchr(const char *str, int c) searches for the last
occurrence of the character c (an unsigned char) in the string pointed to, by the
argument str.
Declaration
Following is the declaration for strrchr() function.
char *strrchr(const char *str, int c)
Parameters
str − This is the C string.
c − This is the character to be located. It is passed as its int promotion, but it is
internally converted back to char.
Return Value
This function returns a pointer to the last occurrence of character in str. If the value is
not found, the function returns a null pointer.
strchr()
Description
The C library function char *strchr(const char *str, int c) searches for the first
occurrence of the character c (an unsigned char) in the string pointed to by the
argument str.
Declaration
Following is the declaration for strchr() function.
char *strchr(const char *str, int c)
Parameters
str − This is the C string to be scanned.
c − This is the character to be searched in str.
Return Value
This returns a pointer to the first occurrence of the character c in the string str, or NULL
if the character is not found.
strncpy()
Description
The C library function char *strncpy(char *dest, const char *src, size_t n) copies up
to n characters from the string pointed to, by src to dest. In a case where the length of
src is less than that of n, the remainder of dest will be padded with null bytes.
Declaration
Following is the declaration for strncpy() function.
char *strncpy(char *dest, const char *src, size_t n)
Parameters
dest − This is the pointer to the destination array where the content is to be
copied.
src − This is the string to be copied.
n − The number of characters to be copied from source.
Return Value
This function returns the final copy of the copied string.
C strcpy()
In this tutorial, you will learn to use the strcpy() function in C programming to copy
strings (with the help of an example).
C strcpy()
The function prototype of strcpy() is:
The strcpy() function copies the string pointed by source (including the null
character) to the destination.
The strcpy() function also returns the copied string.
Syntax of strset()
strset() accepts two parameters.
Fist parameter must be a string whereas second parameter must be
a character.
To use strset() inbuilt string function in C, we need to declare
#include<string.h> header file.
Syntax
strset(str, chr);
C Program - strset()
Let us work through strset() function. In the following program we will
reverse the string using strset() inbuilt string function.
#include <stdio.h>
#include<string.h>
int main()
{
char str[20] = "password";
char chr = '*' ;
strset(str, chr);
printf("str: %s ", str);
return 0;
}
str1: ********
strnset() function in C
The strnset() function is a builtin function in C and it sets the first n characters of a string
to a given character. If n is greater than the length of string, the length of string is used in
place of n.
Syntax:
char *strnset(const char *str, char ch, int n);
Parameters:
str: This is the original string in which some character are replaced by a given
character.
ch: ch represents the given character.
n: n represents the number of character which is replaced by the given
character.
Return Value: It returns the modified string obtained after replacing the first
characters of the given string str.
memset()
Description
The C library function void *memset(void *str, int c, size_t n) copies the
character c (an unsigned char) to the first n characters of the string pointed to, by the
argument str.
Declaration
Following is the declaration for memset() function.
void *memset(void *str, int c, size_t n)
Parameters
str − This is a pointer to the block of memory to fill.
c − This is the value to be set. The value is passed as an int, but the function fills
the block of memory using the unsigned char conversion of this value.
n − This is the number of bytes to be set to the value.
Return Value
This function returns a pointer to the memory area str.
C strcmp()
The strcmp() function compares two strings and returns 0 if both strings are identical.
C strcmp() Prototype
negative if the ASCII value of the first unmatched character is less than the second.
positive integer if the ASCII value of the first unmatched character is greater than the second.
strcmpi() function in C
The strcmpi() function is a built-in function in C and is defined in the “string.h” header
file. The strcmpi() function is same as that of the strcmp() function but the only difference
is that strcmpi() function is not case sensitive and on the other hand strcmp() function is
the case sensitive.
Syntax:
int strcmpi (const char * str1, const char * str2 );
Parameters:
str1: The first string.
str2: The second string.
Returns: This function returns 0 if the given two strings are same, a negative value if the
length of str1 is less then the length of str2 and if the length of str1 is greater then str2
then this function returns a positive value.
Syntax - stricmp()
stricmp() accepts two parameters.
Both parameters must be a string.
To use stricmp() inbuilt string function in C, we need to declare
#include<string.h> header file.
Syntax
stricmp(str1, str2);
fgets()
For a general-purpose text input function in the C programming language, one that reads beyond the
first white space character, try the fgets() function. Here’s the format:
#include <stdio.h>
char * fgets(char *restrict s, int n, FILE *restrict stream);
Frightening, no? That’s because fgets() is a file function, which reads text from a file, as in “file get
string.” That’s how programmers talk after an all-nighter.
Because the operating system considers standard input like a file, you can use fgets() to read text
from the keyboard.
Here’s a simplified version of the fgets() function as it applies to reading text input:
fgets(string,size,stdin);
In this example, string is the name of a char array, a string variable; size is the amount of text to input
plus one, which should be the same size as the char array; and stdin is the name of the standard
input device, as defined in the stdio.h header file.
sscanf()
Description
The C library function int sscanf(const char *str, const char *format, ...) reads
formatted input from a string.
Declaration
Following is the declaration for sscanf() function.
int sscanf(const char *str, const char *format, ...)
Parameters
str − This is the C string that the function processes as its source to retrieve the
data.
format − This is the C string that contains one or more of the following
items: Whitespace character, Non-whitespace character and Format specifiers
A format specifier follows this prototype: [=%[*][width][modifiers]type=]
1
*
This is an optional starting asterisk, which indicates that the data is to be read from the
stream but ignored, i.e. it is not stored in the corresponding argument.
2
width
This specifies the maximum number of characters to be read in the current reading
operation.
3
modifiers
Specifies a size different from int (in the case of d, i and n), unsigned int (in the case of o,
u and x) or float (in the case of e, f and g) for the data pointed by the corresponding
additional argument: h : short int (for d, i and n), or unsigned short int (for o, u and x) l :
long int (for d, i and n), or unsigned long int (for o, u and x), or double (for e, f and g) L :
long double (for e, f and g)
4
type
A character specifying the type of data to be read and how it is expected to be read. See
next table.
c Single character: Reads the next character. If a width different from 1 is specified, char *
the function reads width characters and stores them in the successive locations of
the array passed as argument. No null character is appended at the end.
e, E, f, Floating point: Decimal number containing a decimal point, optionally preceded by a float *
g, G + or - sign and optionally followed by the e or E character and a decimal number.
Two examples of valid entries are -732.103 and 7.12e4
s String of characters. This will read subsequent characters until a whitespace is char *
found (whitespace characters are considered to be blank, newline and tab).
Return Value
On success, the function returns the number of variables filled. In the case of an input
failure before any data could be successfully read, EOF is returned.