write a program in c.
need help
Collapse
This topic is closed.
X
X
-
kevinTags: None -
Nick Keighley
Re: need help
On 10 Jul, 10:14, kevin <k...@nospam.in validwrote:you forgot the magic "p" wordwrite a program in c.
--
Nick Keighley
Error on line 0: Lazy programmer.
-
Wolfgang Draxinger
Re: need help
kevin wrote:
If that's some exercise and you want to cheat, then go towrite a program in c.
<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
--
E-Mail address works, Jabber: hexarith@jabber .org, ICQ: 134682867
Comment
-
santosh
Re: need help
kevin wrote:
Save the program below in a file called test.c. Invoke your favouritewrite a program in c.
compiler and enjoy.
#include "test.c"
main(){}
Comment
-
Keith Thompson
Re: need help
kevin <kev@nospam.inv alidwrites:Ok, done.write a program in c.
If you're interested, the output was:
Qb lbhe bja ubzrjbex
Hope this helps, have a nice day.
--
Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Comment
-
Walter Roberson
Re: need help
In article <g54otd$lo$1@re gistered.motzar ella.org>,
santosh <santosh.k83@gm ail.comwrote:Is this for C89 or C99? If it is for C99 then you need the 'int'>kevin wrote:
>>>write a program in c.
>Save the program below in a file called test.c. Invoke your favourite
>compiler and enjoy.
>
>#include "test.c"
>main(){}
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.
--
"The study of error is not only in the highest degree
prophylatic, but it serves as a stimulating introduction to the
study of truth." -- Walter Lipmann
Comment
-
santosh
Re: need help
Walter Roberson wrote:
The code is broken on purpose. :-)In article <g54otd$lo$1@re gistered.motzar ella.org>,
santosh <santosh.k83@gm ail.comwrote:>>>kevin wrote:
>>>>>>write a program in c.
>>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.
Yes, and lcc-win apparently has a limit of 15. The Intel C compilerRecall, 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.
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.
Comment
-
John J. Smith
Re: need help
kevin wrote:
Easy.write a program in c.
/*
* 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);
}
--
John J. Smith
Homework Expert
Comment
-
Hans Schneider
Re: need help
John J. Smith schrieb:
This program works not with LCC-WIN32 again! Why?>kevin wrote:
>>>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);
>}
lc -ansic -pedantic -unused shadows -O aprog.c
Pedants aren't supported any more :-)
1 error
How do you do that? Not funny!
Comment
-
Jens Thoms Toerring
Re: need help
Hans Schneider <hans@localhost .localdomainwro te:
<program snipped>
This program works not with LCC-WIN32 again! Why?Jacob Navia announced in a recent thread here in clclc -ansic -pedantic -unused shadows -O aprog.c
Pedants aren't supported any more :-)
1 error
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.
Better discuss that with Jacob in personal email (or in the lccHow do you do that? Not funny!
newsgroup) unless you're trolling for another long-winded, use-
less and mostly off-topic thread here in clc;-)
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\______________ ____________ http://toerring.de
Comment
-
Kenneth Brody
Re: need help
kevin wrote:Done. What do I get?>
write a program in c.
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer .h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:ThisIsA SpamTrap@gmail. com>
Comment
-
Hans Schneider
Re: need help
Jens Thoms Toerring schrieb:
Sucks.Hans Schneider <hans@localhost .localdomainwro te:
>
<program snipped>
>>>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
>
>
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.
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?
Comment
-
Richard Heathfield
Re: need help
Hans Schneider said:
<snip>
Yes.Is signed int short bar = 0; valid C?
--
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
Comment
-
Dann Corbit
Re: need help
"Hans Schneider" <hans@localhost .localdomainwro te in message
news:1355811T_d WV9SEqCh@localh ost.localdomain ...sure.Jens Thoms Toerring schrieb:
>>>Hans Schneider <hans@localhost .localdomainwro te:
>>
><program snipped>
>>>>>>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....edants&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?
Q:\>type t.c
/*
* 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);
}
Q:\>cl /W4 /Ox t.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for
80x86
Copyright (C) Microsoft Corporation. All rights reserved.
t.c
Microsoft (R) Incremental Linker Version 8.00.50727.762
Copyright (C) Microsoft Corporation. All rights reserved.
/out:t.exe
t.obj
Q:\>t
a program
dcorbit@DCORBIT 64 /q
$ gcc -W -Wall -ansi -pedantic t.c
dcorbit@DCORBIT 64 /q
$ ./a
a program
dcorbit@DCORBIT 64 /q
$ gcc --version
gcc.exe (GCC) 3.2 (mingw special 20020817-1)
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
dcorbit@DCORBIT 64 /q
As you can see from this diagnostic:
Q:\>splint t.c
Splint 3.1.1 --- 12 Mar 2007
t.c: (in function write)
t.c(14,12): Test expression for while not boolean, type char: baz[bar]
Test expression type is not boolean. (Use -predboolothers to inhibit
warning)
t.c(15,9): Return value (type int) ignored: putchar(baz++[bar])
Result returned by function call is not used. If this is intended, can
cast
result to (void) to eliminate message. (Use -retvalint to inhibit warning)
t.c(10,17): Function exported but not used outside t: write
A declaration is exported, but not used outside this module. Declaration
can
use static qualifier. (Use -exportlocal to inhibit warning)
t.c(17,1): Definition of write
Finished checking --- 3 code warnings
the program relies on an odd feature of the language {as explained in the
C-FAQ}:
6.11: I came across some "joke" code containing the "expression "
5["abcdef"] . How can this be legal C?
A: Yes, Virginia, array subscripting is commutative in C. This
curious fact follows from the pointer definition of array
subscripting, namely that a[e] is identical to *((a)+(e)), for
*any* two expressions a and e, as long as one of them is a
pointer expression and one is integral. This unsuspected
commutativity is often mentioned in C texts as if it were
something to be proud of, but it finds no useful application
outside of the Obfuscated C Contest (see question 20.36).
References: Rationale Sec. 3.3.2.1; H&S Sec. 5.4.1 p. 124,
Sec. 7.4.1 pp. 186-7.
** Posted from http://www.teranews.com **
Comment
-
Ben Bacarisse
Re: need help
Hans Schneider <hans@localhost .localdomainwri tes:
Yes -- odd, but valid. <OT>And I get no error from it in lcc-win32.</OT>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?
--
Ben.
Comment
Comment