need help

W

Wolfgang Draxinger

kevin said:
write a program in c.

If that's some exercise and you want to cheat, then go to
<http://kernel.org>, there you can get the sources of a
particulary good programm written in C.

But don't be surpreised, if you got a bad mark...

If it shall be a bit simpler then a full blown OS kernel:

#include <stdio.h>
int main(int argc, char *argv[])
{
int i;
for(i = 0; i < 42; ++i) {
printf("%d, not the awnser to the question...\n", i);
}
return ++i;
}

That should do it, but I don't think you will profit from that
example.

Seriously: If this is a exercise, and you're a total newbie, then
just crying "help" won't help you at all. Anything people can do
is giving you some written examples of code and some explanation
to it.

Such things are commnly called textbooks and can be found in
buildings called libraries and bought in bookshops, that come
also in online form, one of them being <http://amazon.com>.

But neither, an explanation given here, nor a textbook will take
the work from you. It's still up to you to read the texts and
also to understand them. I highly suggest, you read the book,
and in the case of 'C' that would be "The C Programming
Language" by Kernighan and Ritchie then.

Once you've questions on thing you didn't understand reading the
book, you're welcome to ask here, as long as you give detailed
information about with which part you got a problem.

Wolfgang Draxinger
 
W

Walter Roberson

Save the program below in a file called test.c. Invoke your favourite
compiler and enjoy.

#include "test.c"
main(){}

Is this for C89 or C99? If it is for C99 then you need the 'int'
on main. If it is for C89 then you should return a value from main.

Recall, by the way, that compilers are permitted to impose limits on
the depth of inclusions. For example,
gcc version 3.4.4 20050721 (Red Hat 3.4.4-2)
with default options will expand to a total of 199 instances of main.
 
S

santosh

Walter said:
Is this for C89 or C99? If it is for C99 then you need the 'int'
on main. If it is for C89 then you should return a value from main.

The code is broken on purpose. :)
Recall, by the way, that compilers are permitted to impose limits on
the depth of inclusions. For example,
gcc version 3.4.4 20050721 (Red Hat 3.4.4-2)
with default options will expand to a total of 199 instances of main.

Yes, and lcc-win apparently has a limit of 15. The Intel C compiler
gives this amusing diagnostic:

test.c(1): catastrophic error: #include file "test.c" includes itself
#include "test.c"
^
compilation aborted for test.c (code 4)

BTW "test.c" can be replaced with __FILE__ to make the include directive
immune to file renaming.
 
J

John J. Smith

kevin said:
write a program in c.

Easy.

/*
* aprog.c
*
* "write a program in c."
*
*/

#include <stdio.h>
#define in "\n"
#define c

int write(const char *foo)
{
signed int short bar = 0;
const char *baz = foo;
while(baz[bar]) putchar(bar[baz++]);
return 0;
}

int main(void)
{
return write("a program" in c);
}
 
H

Hans Schneider

John said:
kevin said:
write a program in c.

Easy.

/*
* aprog.c
*
* "write a program in c."
*
*/

#include <stdio.h>
#define in "\n"
#define c

int write(const char *foo)
{
signed int short bar = 0;
const char *baz = foo;
while(baz[bar]) putchar(bar[baz++]);
return 0;
}

int main(void)
{
return write("a program" in c);
}

This program works not with LCC-WIN32 again! Why?

lc -ansic -pedantic -unused shadows -O aprog.c
Pedants aren't supported any more :)
1 error

How do you do that? Not funny!
 
J

Jens Thoms Toerring

This program works not with LCC-WIN32 again! Why?
lc -ansic -pedantic -unused shadows -O aprog.c
Pedants aren't supported any more :)
1 error

Jacob Navia announced in a recent thread here in clc

http://groups.google.com/group/comp...7bd9720d78/7a4bcdc84d952874?q=Pedants&lnk=ol&

that lcc-win no will longer have a '-pedantic' option (or, to be
precise, will output the above text if it's used). Since it's his
compiler he can do whatever he likes with it.
How do you do that? Not funny!

Better discuss that with Jacob in personal email (or in the lcc
newsgroup) unless you're trolling for another long-winded, use-
less and mostly off-topic thread here in clc;-)

Regards, Jens
 
H

Hans Schneider

Jens said:
Jacob Navia announced in a recent thread here in clc

http://groups.google.com/group/comp...7bd9720d78/7a4bcdc84d952874?q=Pedants&lnk=ol&

that lcc-win no will longer have a '-pedantic' option (or, to be
precise, will output the above text if it's used). Since it's his
compiler he can do whatever he likes with it.

Sucks.

But, if I remove -pedantic, it works still not:

lc -ansic -unused -shadows -O aprog.c
Error aprog.c: 14 invalid type specification
1 error, 0 warnings
1 error

Is signed int short bar = 0; valid C?
 
B

Ben Bacarisse

Hans Schneider said:
But, if I remove -pedantic, it works still not:

lc -ansic -unused -shadows -O aprog.c
Error aprog.c: 14 invalid type specification
1 error, 0 warnings
1 error

Is signed int short bar = 0; valid C?

Yes -- odd, but valid. <OT>And I get no error from it in lcc-win32.</OT>
 
K

Kenneth Brody

kevin said:
Cool. Can I see it?

Sure. I charge $125/hour with a 2 hour minimum, so send me $250
and I'll forward you the program.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 
K

kevin

Richard said:
kevin said:


By writing a rot13-decoder. Once you've achieved this, writing a
rot13-*en*coder is relatively simple.

Yes I know, I won first price in a rot13 contest. It is easy to do in
your head because for example 'D' + 13 is always 'Q'.

On my computer at home 'D' is 68 and 'Q' is 81, no problem there.

On my computer at school, 'D' is 196, 'Q' is 216, and 'D' + 13 is 209,
which is 'J'. Problem.

What to do?

I could translate all letters so alphabetical and numerical order is
the same, apply rot13, then translate back. Then I would need a
different code versions on each computer.

Or I could use some gigantic switch. Doesn't look right either.
 
B

Bartc

kevin said:
Yes I know, I won first price in a rot13 contest. It is easy to do in
your head because for example 'D' + 13 is always 'Q'.

On my computer at home 'D' is 68 and 'Q' is 81, no problem there.

On my computer at school, 'D' is 196, 'Q' is 216, and 'D' + 13 is 209,
which is 'J'. Problem.

What to do?

Forget the numeric equivalents. Just memorise the translations so that A
becomes N, B becomes O and so on. This will then work on anything. In fact
after a while you will not need to translate at all. And you can win more
prices.
 
B

Bartc

Hans said:
....
But, if I remove -pedantic, it works still not:

lc -ansic -unused -shadows -O aprog.c
Error aprog.c: 14 invalid type specification
1 error, 0 warnings
1 error

Is signed int short bar = 0; valid C?

I think until recently lccwin didn't allow type specifiers in any order,
even though the C standard rather unwisely didn't prohibit this. Presumably
for historic reasons.

Now lccwin seems to go along with other C compilers rather than take a
stand. So you can now write every declaration in at least N! different ways.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top