Advertisement

Home Work n' printf()

Started by February 08, 2000 12:26 AM
20 comments, last by Wild9eR 24 years, 10 months ago
Hello For my homework I needed to take in a name (first last) and do buch of display stuff with printf(). what I am stuck on is how to get output line that is exactly X2 the length of the last name ex: printf("%(strlen(lastName)*2)s ", lastName); this does not work.....what will?
Job description : Duct Tape
Maybe that is why it''s homework. I don''t think that it is really fair to ask these sorts of questions.

Anyways, I think that you should read up on the proper use of printf().

Good luck.
William Reiach - Human Extrodinaire

Marlene and Me


Advertisement
I would normally agree with you that the object of homework is to learn. Since I obviously don''t know the answer and I cannot find the proper way to do it in the book perhaps you can enlighten me with your holy knowledge and answer the question instead of telling me to go on a snipe hunt.
Job description : Duct Tape
Oh by the way the homework will be invalid if I use any other function besides printf(), scanf(), sizeof, and strlen(). So there dammit help me out I wanna go to bed!
Job description : Duct Tape
First of all, the majority of posters on this board will not do your homework for you, which is exactly what you''re asking us to do. Second, drop the attitude. Gromit was being nice.
If I understand the problem correctly, you can do it with a loop. What do you need to fill the extra space with anyway? You can use the loop to put X characters on the screen... I think this post is too late to help you (unless I got my time zones mixed up again...)

www.trak.to/rdp

Yanroy@usa.com

--------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Yanroy@usa.com

Advertisement
I wasn''t asking for him to do my homework (most of it was finished, that was the last problem). Should I have lied and said I was just playing around with the printf function? Gimmie a break... And yes a loop would have worked (I thought about doing just that BEFORE I asked the question) but since we haven''t covered loops in the class it would not have been accepted. As for Gromit being nice, he caould have simply stated the "no, you cannot do that with printf()" instead of sending me on a snipe hunt. I appreciate him responding; but like I said, he wasn''t helping so why respond at all? Anyways the homework is done (exept for the last problem) so good day to you all.
Job description : Duct Tape
I''m going to be brat here.

If you are using a compiler, it has a manual.

Read it.
Also: if we gave you an answer, they''d know somebody professional did it, so you''d get busted. It''s actually a nifty problem with a couple of solutions, so why don''t you try your best? Maybe your teacher wants to see what kind of intuition you have.
I did read the manual (MSDN, and my C book)

%[flags] [width] [.precision] [{h / l / I64 / L}]type

I could not figure out how to make the width twice that of the string inputed.

I understand that I can simple input
printf("this is my name %10s ", lastName);

but I REALLY don''t know how to make that width specifier dynamic. I''m sitting here looking at the MSDN and I see the * sign, but that does not seem to be what I want. Does it? If thats it someone PLEASE tell me. The homework is turned in and finished but I would like to know how to do this just becuase I don''t already. Sorry if I sounded like a ass in my preivous posts but that first answer DID NOT help me at all. And yes I agree, reading the manual is always a good idea, because if I find it my self I have a much better chance of remebering it. But I looked in the maunal and I am stumped.
Job description : Duct Tape

This topic is closed to new replies.

Advertisement