Author |
Message |
Richard Hayde #1 / 7
|
 Pointers & Arrays
Hi, Why does the first example below work, and not the second?? First Example: char * Test = new char[20]; cin.getline(Test, 20); Second Example: char Test[20]; cin.getline(Test, 20); Thanks, --
Webmaster: http://www.*-*-*.com/ DXOS (My Operating System): http://www.*-*-*.com/ "Ich suche die Antworten, wie viele Leute vor und nach mir. Ich stelle Fragen, aber ich akzeptiere nichts, alle mssen bewiesen werden." --- Outgoing mail from Richard Hayden is certified Virus Free. Checked by AVG anti-virus system ( http://www.*-*-*.com/ ). Version: 6.0.381 / Virus Database: 214 - Release Date: 02/08/2002
|
Sat, 12 Feb 2005 02:17:56 GMT |
|
 |
Joona I Palast #2 / 7
|
 Pointers & Arrays
Quote: > Hi, > Why does the first example below work, and not the second?? > First Example: > char * Test = new char[20]; > cin.getline(Test, 20); > Second Example: > char Test[20]; > cin.getline(Test, 20);
What is new? What is cin.getline()? Methinks you want the comp.lang.c++ newsgroup. --
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++| | http://www.helsinki.fi/~palaste W++ B OP+ | \----------------------------------------- Finland rules! ------------/ "'It can be easily shown that' means 'I saw a proof of this once (which I didn't understand) which I can no longer remember'." - A maths teacher
|
Sat, 12 Feb 2005 02:19:25 GMT |
|
 |
Lew Pitch #3 / 7
|
 Pointers & Arrays
On Mon, 26 Aug 2002 19:17:56 +0100, in comp.lang.c, "Richard Hayden" Quote:
>Hi, >Why does the first example below work, and not the second?? >First Example: >char * Test = new char[20]; >cin.getline(Test, 20);
This isn't ISO standard C Quote: >Second Example: >char Test[20]; >cin.getline(Test, 20);
This isn't ISO standard C either. So, if you can supply the ISO C source for the function called getlin(), referenced from the structure cin, then your question is off topic here. OTOH, if this is C++, then you've got the wrong newsgroup. comp.lang.c++ is down the hall, second door on the left. Lew Pitcher, Information Technology Consultant, Toronto Dominion Bank Financial Group
(Opinions expressed are my own, not my employer's.)
|
Sat, 12 Feb 2005 02:20:50 GMT |
|
 |
Jirka Klau #4 / 7
|
 Pointers & Arrays
[...] Quote: > So, if you can supply the ISO C source for the function called getlin(), ^^^ > referenced from the structure cin, then your question is off topic here.
^^^ No chance then? ;-) Jirka
|
Sat, 12 Feb 2005 02:34:25 GMT |
|
 |
Lew Pitch #5 / 7
|
 Pointers & Arrays
On Mon, 26 Aug 2002 20:34:25 +0200, in comp.lang.c, Jirka Klaue Quote:
>[...] >> So, if you can supply the ISO C source for the function called getlin(), > ^^^
I meant to say "if you can't supply the ISO C source ..." Boy, my typing is getting bad. Quote: >> referenced from the structure cin, then your question is off topic here. > ^^^ >No chance then? ;-) >Jirka
Lew Pitcher, Information Technology Consultant, Toronto Dominion Bank Financial Group
(Opinions expressed are my own, not my employer's.)
|
Sat, 12 Feb 2005 03:24:21 GMT |
|
 |
Dave Near #6 / 7
|
 Pointers & Arrays
On Mon, 26 Aug 2002 19:17:56 +0100, Richard Hayden said: Quote: > Hi, > Why does the first example below work, and not the second?? > First Example: > char * Test = new char[20]; > cin.getline(Test, 20); > Second Example: > char Test[20]; > cin.getline(Test, 20);
Presumably the struct called cin has a function pointer member called getline which accepts a char * and an int as arguments... the first example uses char illegally, which is a syntax error. But both your code segments have issues with uninitialised variables in the absence of context. Also you don't define what "work" means - what behaviour are you expecting, and what behaviour are you seeing? Cheers, Dave. -- David Neary, E-Mail: bolsh at gimp dot org CV: http://www.redbrick.dcu.ie/~bolsh/CV/CV.html
|
Sat, 12 Feb 2005 14:59:27 GMT |
|
 |
Martin Ambuh #7 / 7
|
 Pointers & Arrays
Quote:
> Hi, > Why does the first example below work, and not the second??
We can't tell you, because ... Quote: > First Example: > char * Test = new char[20];
'new' is an undefined identifier leading to a syntax error. Quote: > cin.getline(Test, 20);
You have given no definition of the struct cin or its member pointer to function getline or of the function to which you have made getline point. Quote: > Second Example: > char Test[20]; > cin.getline(Test, 20);
If the mysterious and undefined (or else non-C) struct cin and the associated functions work in the first (no possible in C), there is no obvious reason for it not to work in the second (possible in C) Perhaps you are using the broken and inferior language C++, in which case you have posted to the wrong newsgroup.
|
Sat, 12 Feb 2005 17:08:32 GMT |
|
|
|