Zottel said:
>
I like to use couple of constant in comination with an variable to
change the name of the constant.
The further text show my vainly try:
#define KONST1 13 /*Konstanten festlegen*/
#define KONST2 7
#define KONST2 47
main() {
int c = getchar(), i; /*Variablen definieren und
initialisieren*/
for (i = 1, i <= 3, i++) { /*Einfügen von ASCii Zeichen*/
You meant <, not <=, and you meant semicolons ; ; not commas , ,
putchar(c+KONSTi);
c = getchar();
}
}
I am a newbie in C and I hope this question is not to nasty.
For C to be able to do this, the implementation would have to be able to
maintain a symbol table at runtime, and few implementations do that (I
would guess that a C interpreter might, but most C implementations are
compilers).
Instead, I recommend that you use an array. For example:
#include <stdio.h>
int main(void)
{
int konst[] = { 13, 7, 47 };
int c = getchar();
int i;
for(i = 0; i < 3; i++)
{
putchar(c + konst[i]);
c = getchar();
}
return 0;
}
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999