|
Post by loyalgurl on Oct 26, 2005 3:57:42 GMT 5.5
hi all i need help with pointers in C...... What I want to do is take a set of inputs as strings or int numbers using scanf individually....using pointers. let us c an example...
I want the user to input set of commands like
add abc 10 add ef30 100 update abc 20 print sort print
etc, etc.... Depending on the type of initial command, I have to create an item like abc(if it is add) and then the number 10 corresponding to it... Using command update means that I store 20 instead of the earlier 10 at the location of 10... print is to display and sort to sort the item as well as number according to the item name....I can not use any array ( use pointers) and whenever a new element is to be added I have to use alloc, malloc, etc. etc....
How do I go about doing that? I am pretty clear with the concept of pointers but do not understand how to actually implement them...
Please help thanks a lot in advance
|
|
|
Post by Saurabh Jain on Oct 27, 2005 10:22:38 GMT 5.5
Helllo loyalgurl
look , its not too tough , rigth now i cant give u exact solution by writing c or c++ program , but let me try the steps by which u can try to solve this ...
Look first step is to read a line say add abc 10 thsi can be done by reading a sentence ... Now our main work starts In every command statement there will be three words word no 1 will be command that is add or update second word will be the item name word no 3 will be the intiger which has to be added or updated or other processing
So we have to extract these three words from the given command U must have done simple program to count how many words in sentence if yes same principle can be used that is check the strling length and the spaces between them so word no 1 will be from first to blank space 1 and word no 2 will be from space 1 to space 2 and so on by this process u can extract all words
then the processing which can be done if u can compare the word 1 with ur commands that u have allowed to perform
I think rest is simple try it out good luck otherwise ill try , actually its more than a yaer i touched c c++ anyways program is not tough might be littel lengither but can also be shorten by using functions... but first try it in simple way byeee
|
|