Re: GNU C++ code/concept help needed.
Jyotirmoy Saikia <[email protected]> Tue, 20 Sep 2005 11:49:43 +0530
| Newsgroups | gmane.user-groups.linux.delhi.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Rohit, On 9/19/05, Rohit Kumar <rohitsz2-/[email protected]> wrote: > Greetings there, > > i am very very happy to see the responses :-) > thanks to all and specially Jyotirmoy, Mayank and > Ajay. You're welcome. > all your suggestions worked. > so lesson learnt... > (twice on this list, previously with C and pointers) > > 1. initializing the pointers.. come what may! You should always initialize pointers. But in your case, that was not exactly the problem. You have a little confusion between pointers vs arrays/dynamically alloted memory. You can have pointers; but they should point to some valid storage if you want to keep something in the storage pointed by the pointer. You CANNOT store those characters AT the pointer; but you have to store those at the storage pointed by the pointer. (see the difference between the two) Let me give you an example. You can always give an address for a house, like #256, Rohini, Sector-2. Now that address is not just enough. It may be an empty plot of land. You need a house there before you invite your friends or uncles for a dinner there. You can have the house there already when u bought the plot (it's a statically alloted) or you may get it built (dynamically alloted). The important point is; just the address is not enough; you need a house. Same is the case with pointer. Just the pointer is not enough. You need to have an storage where you'll keep the bytes (for your case, student name, dept etc) Jyotirmoy > 2. (imp) scoping in switch cases can make a > difference! > 3. there has to be a limit to string size being > entered. > > one more Q.. > is there something peculiar towards working of > cin.get(char-pointer,size)? every time i use it, i > need to put a cin.ignore() to stop the console from > overflowing..! > > thanks once again to all, > > regards, > rohit. > > > NAMASTE, i honour the spirit in you which is also in me. > ``````````````````````````````````````````````````````` > http://www.geocities.com/rohitsz2 > >