473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

need help

write a program in c.
Jul 10 '08 #1
24 1369
On 10 Jul, 10:14, kevin <k...@nospam.invalidwrote:
write a program in c.
you forgot the magic "p" word

--
Nick Keighley

Error on line 0: Lazy programmer.
Jul 10 '08 #2
kevin wrote:
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
--
E-Mail address works, Jabber: he******@jabber.org, ICQ: 134682867

Jul 10 '08 #3
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(){}

Jul 10 '08 #4
kevin <ke*@nospam.invalidwrites:
write a program in c.
Ok, done.

If you're interested, the output was:
Qb lbhe bja ubzrjbex

Hope this helps, have a nice day.

--
Keith Thompson (The_Other_Keith) ks***@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"
Jul 10 '08 #5
In article <g5*********@registered.motzarella.org>,
santosh <sa*********@gmail.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.

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
Jul 10 '08 #6
Walter Roberson wrote:
In article <g5*********@registered.motzarella.org>,
santosh <sa*********@gmail.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.
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.

Jul 10 '08 #7
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);
}

--
John J. Smith
Homework Expert

Jul 10 '08 #8
John J. Smith schrieb:
>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);
}
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!

Jul 10 '08 #9
Hans Schneider <ha**@localhost.localdomainwrote:

<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.
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
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
Jul 10 '08 #10
kevin wrote:
>
write a program in c.
Done. What do I get?

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Jul 11 '08 #11
Jens Thoms Toerring schrieb:
Hans Schneider <ha**@localhost.localdomainwrote:

<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?

Jul 11 '08 #12
Hans Schneider said:

<snip>
Is signed int short bar = 0; valid C?
Yes.

--
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
Jul 11 '08 #13

"Hans Schneider" <ha**@localhost.localdomainwrote in message
news:13****************@localhost.localdomain...
Jens Thoms Toerring schrieb:
>Hans Schneider <ha**@localhost.localdomainwrote:

<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?
sure.
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@DCORBIT64 /q
$ gcc -W -Wall -ansi -pedantic t.c

dcorbit@DCORBIT64 /q
$ ./a
a program

dcorbit@DCORBIT64 /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@DCORBIT64 /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 **
Jul 11 '08 #14
Hans Schneider <ha**@localhost.localdomainwrites:
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>

--
Ben.
Jul 11 '08 #15
Keith Thompson wrote:
kevin <ke*@nospam.invalidwrites:
>write a program in c.

Ok, done.

If you're interested, the output was:
Qb lbhe bja ubzrjbex
Looks like rot13. How do you decode that in C?

Jul 13 '08 #16
Kenneth Brody wrote:
kevin wrote:
>>
write a program in c.

Done. What do I get?
Cool. Can I see it?

Jul 13 '08 #17
kevin said:
Keith Thompson wrote:
>kevin <ke*@nospam.invalidwrites:
>>write a program in c.

Ok, done.

If you're interested, the output was:
Qb lbhe bja ubzrjbex

Looks like rot13. How do you decode that in C?
By writing a rot13-decoder. Once you've achieved this, writing a
rot13-*en*coder is relatively simple.

--
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
Jul 13 '08 #18
kevin <ke*@nospam.invalidwrites:
Keith Thompson wrote:
>kevin <ke*@nospam.invalidwrites:
>>write a program in c.

Ok, done.

If you're interested, the output was:
Qb lbhe bja ubzrjbex

Looks like rot13. How do you decode that in C?
Yes, it's rot13. Did you decode it?

Here, I'll make it easy for you:

Do your own homework

--
Keith Thompson (The_Other_Keith) ks***@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"
Jul 13 '08 #19
kevin wrote:
>
Kenneth Brody wrote:
kevin wrote:
>
write a program in c.
Done. What do I get?

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:Th*************@gmail.com>
Jul 14 '08 #20
kevin said:

<snip>
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?
It's called programming.

#define LIM 13

char lookup[UCHAR_MAX + 1] = {0};
char lower[] = "abcdefghijklmnopqrstuvwxyz";
char upper[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int i;
int ch;
assert(UCHAR_MAX < INT_MAX);
for(i = 0; i <= UCHAR_MAX; i++)
{
lookup[i] = i;
}
for(i = 0; i < LIM; i++)
{
lookup[lower[i]] = lower[i + 13];
lookup[lower[i + 13]] = lower[i];
lookup[upper[i]] = upper[i + 13];
lookup[upper[i + 13]] = upper[i];
}

Turning this into a working program, and adding the input/translate/output
stuff, is easy. This technique is guaranteed to work on any system that
satisfies these two conditions:

1) UCHAR_MAX is less than INT_MAX;
2) UCHAR_MAX is sufficiently small to allow the array to be defined.

Whilst these conditions are not met by all machines, it is very likely that
they are met by yours.

--
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
Jul 15 '08 #21
kevin wrote:
Richard Heathfield wrote:
>kevin said:
>>Keith Thompson wrote:

kevin <ke*@nospam.invalidwrites:
write a program in c.

Ok, done.

If you're interested, the output was:
Qb lbhe bja ubzrjbex

Looks like rot13. How do you decode that in C?

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?
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.

--
Bartc


Jul 15 '08 #22
Richard Heathfield wrote:
kevin said:

<snip>
>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?

It's called programming.

#define LIM 13

char lookup[UCHAR_MAX + 1] = {0};
char lower[] = "abcdefghijklmnopqrstuvwxyz";
char upper[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int i;
int ch;
assert(UCHAR_MAX < INT_MAX);
for(i = 0; i <= UCHAR_MAX; i++)
{
lookup[i] = i;
}
for(i = 0; i < LIM; i++)
Why using LIM here...
{
lookup[lower[i]] = lower[i + 13];
lookup[lower[i + 13]] = lower[i];
lookup[upper[i]] = upper[i + 13];
lookup[upper[i + 13]] = upper[i];
.... but not here?

Bye, Jojo
Jul 15 '08 #23
Joachim Schmitz said:
Richard Heathfield wrote:
<snip>
>}
for(i = 0; i < LIM; i++)

Why using LIM here...
>{
lookup[lower[i]] = lower[i + 13];
lookup[lower[i + 13]] = lower[i];
lookup[upper[i]] = upper[i + 13];
lookup[upper[i + 13]] = upper[i];

... but not here?
Sloppiness, my dear fellow - pure sloppiness.

--
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
Jul 15 '08 #24
Richard Heathfield wrote:
Joachim Schmitz said:
>Richard Heathfield wrote:
<snip>
>>}
for(i = 0; i < LIM; i++)

Why using LIM here...
>>{
lookup[lower[i]] = lower[i + 13];
lookup[lower[i + 13]] = lower[i];
lookup[upper[i]] = upper[i + 13];
lookup[upper[i + 13]] = upper[i];

... but not here?

Sloppiness, my dear fellow - pure sloppiness.
I thought so, but also suspected some deep secret hiding here 8-)

Bye, Jojo
Jul 16 '08 #25

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: mike | last post by:
Hello, After trying to validate this page for a couple of days now I was wondering if someone might be able to help me out. Below is a list of snippets where I am having the errors. 1. Line 334,...
5
by: John Flynn | last post by:
hi all i'm going to be quick i have an assignment due which i have no idea how to do. i work full time so i dont have the time to learn it and its due date has crept up on me .. As follows:...
0
by: xunling | last post by:
i have a question about answering ..... this topic is "need help" what do i have to write at te topic line, !after i have klicked the "answer message" button ive tried many possibilities,...
9
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with...
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
16
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client...
8
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the sequence no and item type etc ...but i need only...
0
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need ...
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.