Last active
August 29, 2015 13:58
-
-
Save PanNyaa/10009601 to your computer and use it in GitHub Desktop.
※未完成 strncpyの機能に、n文字分コピーしたあと終端に'\0'を付与するような機能をプラスした関数。第四引数によって'\0'が見つかったときに処理を止めるフラグ(0,1)をON(1)・OFF(0)可能。省略可能でデフォルトは1。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <stdarg.h> | |
#include <stdlib.h> | |
#define strncpynull( ... ) strncpynull_( __VA_ARGS__ ,1 ) | |
int strncpynull_(char*,char*,size_t, ... ); | |
//strncpyっぽい機能+最後に'\0'を付け足す関数 | |
//flagが0だった場合、_Destの'\0'を検知しなくなる。省略すると1 | |
int strncpynull_(char* _Dest,char* _Source,size_t Count, ... ){ | |
va_list list; | |
char *p_Dest,*p_Source,flag; | |
if(_Dest == NULL || _Source == NULL || Count == 0)return -1; | |
p_Dest=_Dest; | |
p_Source=_Source; | |
va_start( list , Count ); | |
flag = va_arg(list,char); | |
if(flag==1){ | |
while(Count--){ | |
if(*p_Dest=='\0' || *p_Source=='\0')break; | |
*p_Dest = *p_Source; | |
p_Dest++;p_Source++; | |
} | |
if( !(*p_Dest=='\0' || *p_Source=='\0') )*p_Dest = '\0'; | |
}else{ | |
while(Count--){ | |
*p_Dest = *p_Source; | |
p_Dest++;p_Source++; | |
} | |
*p_Dest = '\0'; | |
} | |
va_end(list); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
たぶん大丈夫になりました