i got the following code:
#include <stdio.h>
main()
{
int c;
c = getchar();
c = c+1;
putchar(c);
}
and i woul dlike to ask how am I ABLE do the putchar to a new line \n?
thanks
i got the following code:
#include <stdio.h>
main()
{
int c;
c = getchar();
c = c+1;
putchar(c);
}
and i woul dlike to ask how am I ABLE do the putchar to a new line \n?
thanks
Please phrase your question in the form of a complete sentence. Otherwise it's doubtful anyone will know what it is you're trying to say.
[edit] AND DAMNIT, USE CODE TAGS! [/edit]
Quzah.
Hope is the first step on the road to disappointment.
i got the following code:
and i would like to ask how am I ABLE do the putchar to a new line \n?Code:#include <stdio.h> main() { int c; c = getchar(); c = c+1; putchar(c); }
thanks
got it now? blamene?
Guesses
Code:putchar( '\n' );
What I was trying to get you to do, is tell us exactly what it is you wanted to do. Like so:
Or perhaps:Hi, I have this code, and I want to make it so when I call putchar, it puts it on a seperate line.
See? Two different questions, both of which could have been what you were asking. I still don't know what it is you're trying to do. That's why it helps if you're actually clear. It is your job as a person seeking help to be clear as to what you want help with, so we can actually help you.Hi, I have this code, and I want to put a newline. How do I do that?
Otherwise we have to simply guess. Or chew you out. One is more fun than the other. Guess which.
Quzah
Hope is the first step on the road to disappointment.
PHP Code:
int i;
char c='a';
putchar('\n');
for(i=0;i<26;i++)
{
putchar(c);
c++;
}
putchar('\n');
Microsoft is merely an illusion, albeit a very persistant one.
Or more simply:
Code:#include <stdio.h> int main(void) { char c; for(c = 'a';c <= 'z';++c) putchar(c); putchar('\n'); return 0; }
If you understand what you're doing, you're not learning anything.
Of course both solutions begs the question: What happens when you are on a system where 'a' to 'z' is not contigious?
They also beg the question, what does this have to do with the origional poster's question? Unless of course that was actually their question. But since they didn't word it so it was actually understandable, we may never know.
Quzah.
Hope is the first step on the road to disappointment.
Nothing much worse than could happen with the OP's original code.Originally Posted by Thantos
If you understand what you're doing, you're not learning anything.
You know it'd be kinda funny to run that code on a system where 'z' < 'a'. Think of the fun that could be had!
That's more a compiler issue, and rare one because all compilers implement, or should implement, the ascii table.Originally Posted by Thantos
cogeek, if you want to make your putchar to write a '\n' which is 13 ascii, you must insert a char with ascii 12, which I think it's not possible because all chars from 0 to 31 are control chars used by the platform. chars greater than 31 are used for text printing.
Last edited by xErath; 11-19-2004 at 12:50 PM.
This is really off base. The C standard is not written around the ASCII table. Functions like isupper(), islower(), isdigit(), etc., are there to maintain compatibility between system that are and aren't using the ASCII table.Originally Posted by xErath
Doing putchar('\n') is going to work on a system whether or not it uses ASCII. However, putchar(12) (or 13? I'm not sure why you jumped from 13 to 12) is not necessarily going to work on all systems. '\n' isn't even ASCII value 13. It's ASCII value 10.
EDIT: Ahh, I just realized you were suggesting doing putchar(012) (or putchar('\12')), not putchar(12) since 12 octal is 10 decimal.
Last edited by itsme86; 11-19-2004 at 01:12 PM.
If you understand what you're doing, you're not learning anything.
I suggest you do a board search. I remember Salem posting the name of an IBM system that doesn't have contigious 'a' - 'z'.That's more a compiler issue, and rare one because all compilers implement, or should implement, the ascii table.
EBCDIC is one such coding system for characters which doesn't have contiguous letters