From what I understand cin.getLine gets the first char(which I think it a pointer) and then gets that the length. I have used it when cin for a char. I have a function that is returning a pointer to the first char in an array. Is there an equivalent to get the rest of the array into a char that I can use the entire array. I explained below what I am trying to do. The function works fine, but if it would help I could post the function.
cmd_str[0]=infile();// get the pointer from a function
cout<<"pp1>";
cout<< "test1"<<endl;
// cin.getline(cmd_str,500);something like this with the array from the function
cout<<cmd_str<<endl; this would print out the entire array
cout<<"test2"<<endl;
length=0;
length= shell(cmd_str);// so I could pass it to this function
First, if
cmd_stris an array ofcharandinfilereturns a pointer to a string, that first assignment will give you an error. It tries to assign a pointer to a single char.What you seem to want is
strncpy:I make sure to add the string terminator to the array, because if
strncpycopies allARRAY_LENGTH - 1characters, it will not append the terminator.If
cmd_stris a proper array (i.e. declared likechar cmd_str[ARRAY_LENGTH];) then you can usesizeof(cmd_str) - 1instead ofARRAY_LENGTH - 1in my example. However, ifcmd_stris passed as a pointer to a function, this will not work.