[Dev-C++] How do I pass arrays of data from a function?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Rob P. <py...@ea...> - 2002-10-21 20:48:45
|
Hi all,
I'm in the process of trying to teach myself C and C++ but don't have
anyone to ask questions. I hope you all can answer them.
I am using Dev-C++ (4.9.6.0) on NT4 SP6a.
I am collecting a character stream from the keyboard and storing it in a
character array from within a function. When I try to pass this back up to
the calling program, I want to put this data also into an array.
Here is the code I have :
parts of the program that call the function:
/* fn() prototypes */
char keybd_input();
int main()
{
char ShellName[4096][100];
char getShellName[100];
cout<<"Please enter the shell name: ";
*getShellName = keybd_input(); // get the keyboard characters
ShellName[x] = getShellName; // is this the where I'm doing it wrong?
cout<<"ShellName["<<x<<"] = "<<ShellName[x]<<endl;
for (x=0; x<ShellCount; x++)
{
ofstream a_file(getFileName, ios::app); /* opens a text file to append
to */
a_file<<ShellIndex[x]<<"\t";
a_file<<"\n";
a_file.close();
}
}
the function:
char keybd_input()
{
int x ; // counter var
char getKeyString[100]; // character array from keyboard
cout<<"Please enter a long string: ";
x=0;
while(( getKeyString[x] = getchar() ) != '\n')
{
getKeyString[x];
x++;
}
return *getKeyString;
}
My problem is that I am only getting the first character of the data passed
back from the function.
Any ideas on how to fix this?
Your help would be appreciated.
Thanks,
--->Rob
|