すべてのMACROSをその値に置き換えるコードを書いています。マクロMAXの値が1000の場合、コードでは1000に置き換える必要があります(MACROSが行の最初の単語である場合、その行ではMACROSは置き換えられない場合を想定しています。その場合は別の方法で処理されます。
//Code to replace MACROS BY THEIR VALUES
//line contains the actual one line of the code.
//line is initialized to contain as maximum number of charectos(say 100).
//SrcStr is the macro and destStr is its value.
//This block will be looped for all lines.
char* p;
p = strstr(line,srcStr);
if(p != NULL) //if the srcString is found
{
if(strlen(p) != strlen(line)) //special case
{
if( isalnum(*(p-1)) == 0 && isalnum( *(p+strlen(srcStr)))==0 )
// if the next char and prev char to our macro is not a alphabets or digits
{
/*As answered by medo42 (below)*/
memmove(p+strlen(destStr), p+strlen(srcStr),strlen(p+strlen(srcStr)+1);
memcpy(p,destStr,strlen(destStr));
}
}
else
{/* handle differently*/}
}
私は初めて使用memmove
しているので、上記のコードが安定していて正しく動作するかどうかは疑問です。memcopy
上記のコードは正しいですか?そして、上記のコードはすべての入力の場合で安定していますか?