私はあなたが混乱していることを感じるので、私はあなたのための例作ら:
#include <iostream>
int main() {
char inp[4] = {'O','I','L', '\0'};
int lll = 4;
// initialize elements of 'ARR' to 0 for safety
char ARR[4] = {0};
int subscount = 0;
// dynamic allocation, DO NOT forget to de-allocate
char* issub = new char[lll];
// copy every element of 'inp' to 'issub'
for(int i=0;i<lll;i++) {
issub[i]=inp[i];
}
// this will copy where '*issub' points to,
// that is the 'issub[0]', to 'ARR[subscount]'
ARR[subscount] = *issub;
std::cout << ARR << "\n"; // prints: O
// you can use a for loop as before to copy the contents,
// from 'inp', 'issub' to 'ARR'
// However, we will do something different here,
// so I am de-allocating 'issub'
delete [] issub;
// We will use an array of pointers, with size 2,
// thus it will have two pointers in total.
char* ptr_arr[2];
// Assign the first pointer to 'inp'
ptr_arr[0] = &(inp[0]);
std::cout << ptr_arr[0] << "\n"; // prints OIL
// we don't use the second pointer,
// set it to NULL
ptr_arr[1] = NULL;
return 0;
}
希望に役立ちます(それは実際にかなりstd::stringを使用しなければならないC++、より、Cのことを思い出します)。
nullで終了する文字列で更新されました。 What is a null-terminated string?
INPは、範囲外のインデックスを使用してアクセスされているので、M.M
あなたのコード@おかげで、悪いです! – Poriferous
正確に何をしたいですか? 'ARR'のすべてのセルを' inp'、**または**と同じになるように 'ARR [subsount]'にポインタを置くとその単語を指し示しますか? – gsamaras
@gsamaras inp –