This header provides functions that perform string operations.
void *memchar(const void *buf,
int c, size_t num); |
searches for character c in the first
num bytes of buf, if c found returns a pointer to the
first occurrence, otherwise returns NULL |
int memcmp(const void *s1, const void *s2,
size_t num); |
compares the first num bytes of s1 and s2, returns
an integer indicating the relationship of s1 and s2 |
void *memcpy(void *dest, const vid *source,
size_t num); |
copies num bytes from source to dest, does not ensure
that overlapping regions of memory are correctly copied,
returns a pointer to dest |
void *memmove(void *dest, const void *source,
size_t num); |
copies num bytes from source to dest, if regions of
memory overlap, these regions are copied before being
overwritten |
void *memset(void *s, int c, size_t num); |
sets the first num bytes of s to a specific character
returns a pointer to s |
void *strcat(char *dest, const char *source); |
appends source to dest, terminating the new string
with a null character |
void *strchr(const char *s, int c); |
returns a pointer to the first occurrence of character
c in string s |
int strcmp(const char *s1, const char *s2); |
compares strings s1 and s2 and returns a value representing
their relationship |
int strcoll(const char *s1, const char *s2); |
similar to strcmp |
char *strcpy(char *dest, const char *source); |
copies string source to dest |
sizt_t strcspn(const char *s1, const char
*s2); |
returns the index for the first character in s2 that
belongs to the set of characters in s2 |
char *strdup(const char *s); |
allocates storage space for a copy of string s and
copies string s o this new location, returns a pointer
t the new copy of s |
char *strerror(int errnum); |
maps errnum to an error message, returning a pointer
to a string |
size_t strlen(const char *s); |
returns the length of string s |
char *strncat(char *dest, const char *source,
size_t num); |
appends up to num characters from string source to
string dest, terminating the new string with a null
character, returns a pointer to the new string |
int strncmp(const char *s1, const char *s2,
size_t num); |
compares up to num characters from string s1 and s2
and returns a value representing their relationship |
char *strncpy(char *dest, const char *source,
size_t num); |
copies up to num bytes from string source to string
dest, returns a pointer to dest |
char *strnset(char *s, int ch, size_t num); |
sets up to num bytes of string s to character ch |
char *strrchr(const char *s, int c); |
returns a pointer to the last occurrence of character
c in string s |
schar *strrev(char *s); |
reverses the order of the characters in string s (except
for the terminating null character), returns a pointer
to string s |
char *strset*char *s, int ch); |
sets the bytes of string s to character ch |
size_t strspn(const char *s1, const char *s2); |
returns the index of the first character in s1 that
does not belong to the set of characters in s2 |
char *strstr(const char *s1, cosnt char *s2); |
returns the address of the first occurrence of string
s2 in s1 |
char *strtok(char *s1, const char *s2); |
separates string s1 into a series of tokens, with
string s2 as the set of delimiters for the tokens, returns
a pointer to token |
size_t strxfrm(char *s1, const char *s2, size_t
n); |
copies up to n bytes from string s2 to string s1,
returns a pointer to s1 |
|
|
/* Domonstrates the use of the strcpy() function
Written by Christopher Krawczyk
Date: 25-12-2002
*/
#include <string.h>
#include <stdio.h>
int main(void)
{
char string[20];
int age = 0;
printf("\t\tThe Age Decider\n\n");
printf("Please enter your
age in years\n\n");
scanf("%d", &age);
if (age > 12 && 20
> age)
strcpy(string,
"You are a teenager");
else if (age < 13)
strcpy(string,
"You are a kid");
else
strcpy(string,
"You are an adult");
printf("\n%s", string);
return 0;
}