char* mystrncpy(char* strdst, const char* strsrc, int count)
{
char *ret = strdst
while (count>0 &&*strsrc)
{
*strdst = *strsrc
strdst++
strsrc++
count--
}
*strdst = 0
return ret
}
unsigned int mystrlen(const char* str)
{
unsigned int ret = 0
while (*str)
{
橡旁胡 ret++
启闷 str++
}
return ret
}
char* mystrlwr(char* str)
{
char* ret = str
while(*str)
{
if (*str >= 65 &&*str <= 90)
*str += 32
str++
}
return ret
}
void main()
{
char strTest[] = "1234567890ABCDEFGabcdefg"
char strResult[100]
printf("Test mystrncpy for 15 characters: %s\n", mystrncpy(strResult, strTest, 15))
printf("Test mystrncpy for 90 characters: %s\n", mystrncpy(strResult, strTest, 90))
printf("Test mystrlen: %d\n", mystrlen(strTest))
printf("Test mystrlwr: %s\n", mystrlwr(strTest))
}
/****char *strcat(dst, src) - concatenate (append) one string to another
*
*Purpose:
* Concatenates src onto the end of dest. Assumes enough
* space in dest.
*
*Entry:
* char *dst - string to which "src"和激 is to be appended
* const char *src - string to be appended to the end of "dst"
*
*Exit:
* The address of "dst"
*
*Exceptions:
*
*******************************************************************************/
char * __cdecl strcat (
char * dst,
const char * src
)
{
char * cp = dst
while( *cp )
cp++ /* find end of dst */
while( *cp++ = *src++ ) /铅亩* Copy src to end of dst */
return( dst ) /* return dst */
}
/***
*char *strcpy(dst, src) - copy one string over another
*
*Purpose:
* Copies the string src into the spot specified by
* destassumes enough room.
*
*Entry:
* char * dst - string over which "src" is to be copied
* const char * src - string to be copied over "dst"
*
*Exit:
* The address of "dst"
*
*Exceptions:
*******************************************************************************/
char * __cdecl strcpy(char * dst, const char * src)
{
char * cp = dst
while( *cp++ = *src++ )
/* Copy src over dst */
return( dst )
}
//以上是微软的实现,更多的到VC++安装盘下CRT目槐棚森录找吧
#include<stdio.h>#include<string>
void strlwr_trans(char *str){
int i=0
while(str[i]!='\0'){
if(str[i]>='A'&&str[i]<='Z')
printf("宏扰%c"哗绝旅,str[i]+32)
else printf("%c",str[i])
i++
}
}
void strupr_trans(char *str){
int i=0
while(str[i]!='\0'){
if(str[i]>='a'&&str[i]<='z')
printf("%c",str[i]-32)
else 乱凳printf("%c",str[i])
i++
}
}
int main(){
char str[100]
scanf("%s",str)
strupr_trans(str)
printf("\n")
strlwr_trans(str)
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)