Hey, I've just finished Day 14 of Sam's Teach Yourself C in 21 Days. I like coding a lot more than learning, so it took me more than two weeks to finish this one - especially when I was thinking of switching to another language... Anyways, I need some help with the exercises -
Can you "unget" more than one character at a time with ungetc()? Can you "unget" the EOF
character?
I guess you can't unget more than one character, because ungetc() take an integer as an argument. Well, you can use a loop or something but that doesn't count. As about the EOF character, what's it's escape sequence? And, can you unget it?
Which of the following are valid type specifiers?
a. "%d"
b. "%4d"
c. "%3i%c"
d. "%q%d"
e. "%%%i"
f. "%9ld"
I know that a is, but the rest kinda confuse me. I didn't read the chapter too well and I'm too lazy to do it because it's too long. Can you please explain which are valid, and why?
Sorry to be too lazy to find it myself...
Thanks, Mike.
2 replies to this topic
#1
Posted 12 December 2010 - 07:30 AM

There is no problem that cannot be solved by the use of high explosives.
|
|
|
#2
Posted 12 December 2010 - 08:22 AM
All except d are valid. Didn't know %i exsists in C aswell (in Python does) and it's for integers. %% will print % on screen.
"%4d" // this means that output is width 4 "%04d" // this will fill blanks with zeroes
printf("12/345 is %08.4f%%", (12 / 345.) * 100);
In example above we say we want leading zeros, total of 8 characters width and 4 of those are for decimal part.
A conclusion is where you got tired of thinking.
#define class struct // All is public.
#3
Posted 12 December 2010 - 08:24 AM
Thanks. Now how about the first one?

There is no problem that cannot be solved by the use of high explosives.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









