intを返すC関数を作成しようとしていますが、その過程で変数として渡されたchar*が入力されます。私が試していることの基本的な例は次のとおりです。
int myMethod(int input, char* output, int outMaxLen) {
int outValue = input * 5;
if (out < 10) strcat(output, "A small number");
else if (out < 20) strcat(output, "A medium number");
else strcat(output, "A large number");
}
main.c:
char* myMethodOutput;
int myMethodInt = myMethod(2, myMethodOutput, 15);
printf("%d %s", myMethodInt, myMethodOutput);
実行すると、整数が画面に表示されますが、テキストは表示されません。
outMaxLen変数は、char *パラメーターをチェックして、出力文字列を収容するのに十分な大きさであることを確認することを目的としています。
strcat()と同様に、私はstrcpy()とstrncpy()を試しましたが、まったく役に立ちませんでした。strcat()はコンソールにテキストを表示せず、strcpy()とstrncpy()はメッセージEXC_BAD_ACCESSでデバッガーを呼び出します。
strcpy_s関数を使用してWindowsAPIでこれを正常に管理できましたが、現在UNIXボックスで試しています。私はおそらく非常に基本的なものが欠けています!