0% found this document useful (0 votes)
44 views

C Isdigit : Function Prototype of Isdigit

The C isdigit() function checks whether a character is a numeric character (0-9) or not. It takes an integer as an argument, converts it to its ASCII value internally, and returns a non-zero integer if the character is numeric or 0 if it is not numeric. It is defined in the <ctype.h> header file.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

C Isdigit : Function Prototype of Isdigit

The C isdigit() function checks whether a character is a numeric character (0-9) or not. It takes an integer as an argument, converts it to its ASCII value internally, and returns a non-zero integer if the character is numeric or 0 if it is not numeric. It is defined in the <ctype.h> header file.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

C isdigit()

The isdigit() function checks whether a character is numeric character (0-9) or not.

Function Prototype of isdigit()

int isdigit( int arg );

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.

It is defined in <ctype.h> header file.

C isdigit() Return value


Return Value Remarks

Non-zero integer ( x > 0 ) Argument is a numeric character.

Zero (0) Argument is not a numeric character.


C strcat()
In C programming, the strcat() function contcatenates (joins) two strings.

The function definition of  strcat()  is:

char *strcat(char *destination, const char *source)

It is defined in the  string.h  header file.

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:

char* strcpy(char* destination, const char* source);

 The  strcpy()  function copies the string pointed by  source  (including the null
character) to the destination.
 The  strcpy()  function also returns the copied string.

The  strcpy()  function is defined in the  string.h  header file.


strset() In C
strset() takes two parameters say str and chr. Here str is a string
whereas chr is a character. strset() will replace every characters in a
string with some user metioned character in chr.

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

int strcmp (const char* str1, const char* str2);

The  strcmp()  function takes two strings and returns an integer.

The  strcmp()  compares two strings character by character.


If the first character of two strings is equal, the next character of two strings are
compared. This continues until the corresponding characters of two strings are
different or a null character  '\0'  is reached.
It is defined in the  string.h  header file.

Return Value from strcmp()


Return Value Remarks

0 if both strings are identical (equal)

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.

Note: This is a non-standard function that works only with older versions of


Microsoft C.
stricmp() In C
Purpose of stricmp()
stricmp() is one of the inbuilt string function in c programming
which is used to compare two strings without any discrimination
between uppercase and lowercase letters, if the strings are
same, it returns 0. Otherwise it returns a nonzero 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=]

Sr.No Argument & Description


.

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.

fscanf type specifiers


type Qualifying Input Type of
argument

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.

d Decimal integer: Number optionally preceded with a + or - sign int *

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).

u Unsigned decimal integer. unsigned


int *

x, X Hexadecimal Integer int *


 other arguments − This function expects a sequence of pointers as additional
arguments, each one pointing to an object of the type specified by their
corresponding %-tag within the format string, in the same order.
For each format specifier in the format string that retrieves data, an additional
argument should be specified. If you want to store the result of a sscanf
operation on a regular variable you should precede its identifier with the
reference operator, i.e. an ampersand sign (&), like: int n; sscanf (str,"%d",&n);

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.

You might also like