I am a beginning ISE student taking a C++ programming class and am having trouble with the simplest things. I need to write a program that reads in an address in a single line of text then outputs that address in the appropriate form.
john doe # 1234 main st. # los angeles # california # 90129
1234 Main St.
Los Angeles, California 90129
So I've been playing with it and get to the point of how to read the information that I need out of the single line. I get I write a getline for every part (name, street...) but after the input "john doe # 1234 main st. # ... how does the program ditinguish which part is name and which part is street and how do I extract each part to use it later?
The file better set up so each field is entered in the in the same order. Otherwise you're SOL (usually). Since you know how the file is set up, you know which field comes first, which comes second, etc.
just throwing it out there and dont know if this is right but here goes nothing:
cout << "Enter you address starting with your name then street then city then state then zip code, seperate each section with a #, for example name # street # ... then after you have entered everything enter a period after the zip code to ensure you are done.";
This is what i put together so far, it comes out with a lot of errors that I dont understand and it could be i just dont really understand what I need to be doing. If there are any blatent mistakes any comments are greatly appreciated even if they are "you're dumb and this is totally wrong" At least i know I'm not doing it right and I can try again. Thanks guys
using namespace std;
void address(char name, char street, char city, char state, char zip);
void address(char name, char street, char city, char state, char zip)
cout<<"Enter your address starting with your name then street then
city then state then zip code, seperate each section with a
#, example name # street # city # ... then after the zip
code is entered enter a period.";
cin.getline (name, 20, '#');
cin.getline (street, 20, '#');
cin.getline (city, 20, '#');
cin.getline (state, 20, '#');
cin.getline (zip, 6, '.');
after this I will do another function that will print out the info in a proper form like the one in my first message but that shouldnt be hard at all so I didnt bother putting it down.
Your function, as written, is getting only single characters as the arguments, and since they are passed by value, nothing in the function will change them in any useful way. Your parameters need to be arrays of char, as in:
alright so I fixed everything and tried to compile it and it worked. The only problem now is that when I try and run the program absolutely nothing comes up I would expect it to at least ask me for the address but it doesnt. I have the same as the other thing but I added  after all the char and that made it compile but if you have a reason why nothing would come out when I ran the program please let me know
so the program runs and gets all the information out but now I need to be able to out put them in the right for and I'm having trouble with that. right now I have:
cout << " The address you entered is: \n";
cout << name;
cout << street;
cout << city;
cout << state;
cout << zip;
I've tried just about everything i can think of to make it appear in the right form but none of it has worked, so I put it back in the first basic form that I had it. If you could suggest a way to drop the next line of text down to the next line after name and such that would be great.