473,503 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

500 C sample Programs

HiTechSkill.Com offers free information, tests, and sample interview
questions that will help to improve your information technology skills.
http://www.hitechskill.com

Apr 9 '06 #1
10 5715
www.hitechskill.com wrote:

HiTechSkill.Com offers free information, tests, and sample interview
questions that will help
to improve your information technology skills.
http://www.hitechskill.com


500 C sample Programs! Let the corrections begin!

/* program no : 1 */
/* purpose : display the message */
/* date of written : 14/12/2004 */

#include <stdio.h>

void main()
{
printf("%s"," welcome to c programming writting");
}
/*************************/

1. void main is a nonportable type for main.
Code like this needs to say what implementation it's for.
2. main, defined with empty parentheses
is an obsolecent feature of the language.
3. A text stream that doesn't end in a newline character
is nonportable, and printf with a %s,
is a slightly overconvoluted way of outputting
a that particular string litteral.
4. There's no return statement, which is allowable in C99,
but not C89.

/* program no : 2 */
double radius=0.0,area;
printf("%lf", area);

1. All the same problems as program number 1 and more.
2 %lf is allowed in C99 as the format specifier for double,
but the right printf format specifier for double in both
C89 and C99, is %f.

/* program no : 3 */
1. All the same problems as program number 2.

Skipping past all the nearly identical programs to ...

/* program no : 22 */
/* purpose : read and print upper to lower */

printf("%c", any+32);

1. All the same problems as program number 1 plus
2. A program that has the stated purpose of this one,
really really should show how to use the tolower function.

"Basic (50 programs)" is a bad choice of names,
for a link to a list of 25 programs.
"While Loops(100 programs)" and "For Loops(100 programs)"
have all the same problems repeated over and over.

At this point, I'm assuming that all the programs
have at least all the same problems as program number 1.

/* program no : 231*/
getch();

getch isn't part of standard C and there's an apparent typo
which causes no files to be #included.

These four links are all the same:
Functions (50 programs)
Pointers (100 programs)
Files(100 programs)
Unix Commands(25programs)

--
pete
Apr 9 '06 #2
pete wrote:
1. void main is a nonportable type for main. [...] 4. There's no return statement, which is allowable in C99,
but not C89.


Even on implementations which document 'void' as a valid return type
for main() ?

Apr 9 '06 #3
pete wrote:
www.hitechskill.com wrote:

HiTechSkill.Com offers free information, tests, and sample interview
questions that will help
to improve your information technology skills.
http://www.hitechskill.com


500 C sample Programs! Let the corrections begin!

/* program no : 1 */
/* purpose : display the message */
/* date of written : 14/12/2004 */

#include <stdio.h>

void main()
{
printf("%s"," welcome to c programming writting");
}
/*************************/

1. void main is a nonportable type for main.
Code like this needs to say what implementation it's for.
2. main, defined with empty parentheses
is an obsolecent feature of the language.
3. A text stream that doesn't end in a newline character
is nonportable, and printf with a %s,
is a slightly overconvoluted way of outputting
a that particular string litteral.
4. There's no return statement, which is allowable in C99,
but not C89.

/* program no : 2 */
double radius=0.0,area;
printf("%lf", area);

1. All the same problems as program number 1 and more.
2 %lf is allowed in C99 as the format specifier for double,
but the right printf format specifier for double in both
C89 and C99, is %f.

/* program no : 3 */
1. All the same problems as program number 2.

Skipping past all the nearly identical programs to ...

/* program no : 22 */
/* purpose : read and print upper to lower */

printf("%c", any+32);

1. All the same problems as program number 1 plus
2. A program that has the stated purpose of this one,
really really should show how to use the tolower function.

"Basic (50 programs)" is a bad choice of names,
for a link to a list of 25 programs.
"While Loops(100 programs)" and "For Loops(100 programs)"
have all the same problems repeated over and over.

At this point, I'm assuming that all the programs
have at least all the same problems as program number 1.

/* program no : 231*/
getch();

getch isn't part of standard C and there's an apparent typo
which causes no files to be #included.

These four links are all the same:
Functions (50 programs)
Pointers (100 programs)
Files(100 programs)
Unix Commands(25programs)


I think he was hungover on 1/1/2005
--
==============
Not a pedant
==============
Apr 9 '06 #4
"Harald van D?k" wrote:
pete wrote:
1. void main is a nonportable type for main.

[...]
4. There's no return statement, which is allowable in C99,
but not C89.


Even on implementations which document 'void' as a valid return type
for main() ?


That's why pete wrote "nonportable" and not "illegal".

regards
John
Apr 9 '06 #5
=?utf-8?B?SGFyYWxkIHZhbiBExLNr?= wrote:

pete wrote:
1. void main is a nonportable type for main.

[...]
4. There's no return statement, which is allowable in C99,
but not C89.


Even on implementations which document 'void' as a valid return type
for main() ?


Code which intended to compile on some platforms but not others,
is nonportable code. That's what "nonportable" means.
If there were no allowances for implementations which
document other types for main(),
then the code would just simply be undefined.
By contrast:

/* BEGIN program no : 1B */
/* purpose : display the message */

#include <stdio.h>

int main(void)
{
puts("welcome to c programming writting");
return 0;
}

/* END program no : 1B */

.... program 1B is highly portable, in C89 and C99.

K&R C is pretty much a defunct language these days.

--
pete
Apr 9 '06 #6
John F wrote:
"Harald van D?k" wrote:
pete wrote:
1. void main is a nonportable type for main.

[...]
4. There's no return statement, which is allowable in C99,
but not C89.


Even on implementations which document 'void' as a valid return type
for main() ?


That's why pete wrote "nonportable" and not "illegal".


pete wrote 'not' 'allowable', not nonportable, for the missing return
statement I was asking about.

Apr 9 '06 #7
On 2006-04-09, pete <pf*****@mindspring.com> wrote:
=?utf-8?B?SGFyYWxkIHZhbiBExLNr?= wrote:

pete wrote:
> 1. void main is a nonportable type for main.

[...]
> 4. There's no return statement, which is allowable in C99,
> but not C89.


Even on implementations which document 'void' as a valid return type
for main() ?


Code which intended to compile on some platforms but not others,
is nonportable code. That's what "nonportable" means.
If there were no allowances for implementations which
document other types for main(),
then the code would just simply be undefined.
By contrast:

/* BEGIN program no : 1B */
/* purpose : display the message */

#include <stdio.h>

int main(void)
{
puts("welcome to c programming writting");
return 0;
}

/* END program no : 1B */

... program 1B is highly portable, in C89 and C99.

K&R C is pretty much a defunct language these days.


Could you expand on that? Do you mean their style, the first edition,
the second edition, the non standard examples? Which is defunct?
(Considering there are billions of lines of code out there on working,
maintained platforms which are based on their programmers K&R based
styles.).
Apr 9 '06 #8
=?utf-8?B?SGFyYWxkIHZhbiBExLNr?= wrote:

John F wrote:
"Harald van D?k" wrote:
pete wrote:
> 1. void main is a nonportable type for main.
[...]
> 4. There's no return statement, which is allowable in C99,
> but not C89.

Even on implementations which document
'void' as a valid return type
for main() ?


That's why pete wrote "nonportable" and not "illegal".


pete wrote 'not' 'allowable', not nonportable, for the missing return
statement I was asking about.


You are correct that a return 0 statement
would be wrong for such a case.

--
pete
Apr 9 '06 #9
Richard G. Riley wrote:

On 2006-04-09, pete <pf*****@mindspring.com> wrote:
=?utf-8?B?SGFyYWxkIHZhbiBExLNr?= wrote:

pete wrote:
> 1. void main is a nonportable type for main.
[...]
> 4. There's no return statement, which is allowable in C99,
> but not C89.

Even on implementations which document 'void' as a valid return type
for main() ?


Code which intended to compile on some platforms but not others,
is nonportable code. That's what "nonportable" means.
If there were no allowances for implementations which
document other types for main(),
then the code would just simply be undefined.
By contrast:

/* BEGIN program no : 1B */
/* purpose : display the message */

#include <stdio.h>

int main(void)
{
puts("welcome to c programming writting");
return 0;
}

/* END program no : 1B */

... program 1B is highly portable, in C89 and C99.

K&R C is pretty much a defunct language these days.


Could you expand on that? Do you mean their style, the first edition,
the second edition, the non standard examples? Which is defunct?
(Considering there are billions of lines of code out there on working,
maintained platforms which are based on their programmers K&R based
styles.).


"K&R C" refers to the language
described in the first edition from 1978.

That language is much more different from C89,
than C89 is from C99.

There's no void type, no long double type.
There's no prototypes.
stdio is the whole standard library.

I'm sure there's a few more differences,
but I don't write in that language,
so I'm not completely familiar with all of the differences.

--
pete
Apr 9 '06 #10
On Sun, 9 Apr 2006 15:13:41 +0200, in comp.lang.c , "Richard G. Riley"
<rg****@gmail.com> wrote:
On 2006-04-09, pete <pf*****@mindspring.com> wrote:
K&R C is pretty much a defunct language these days.


Could you expand on that? [...] Which is defunct?


He means K&R C. If you're unsure what that means, it refers to
pre-standard C. Not the style, but the language.
Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Apr 9 '06 #11

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

Similar topics

8
2569
by: Peter Nolan | last post by:
Hi All, I have written some software that performs ETL processing to load data warehouses. Each program accepts a set of parameters and returns 0 or 1 to the win/unix shell to indicate success or...
1
1513
by: Rhino | last post by:
What is the correct way to notify the tech writers that one of the sample programs has errors in it? Unless I am mistaken, there is an error in the DtLob.java program in the V8.1 Java/JDBC...
2
2490
by: Martin Wingelaar | last post by:
I would like to play around with BLOB and CLOB's and need the sample programs compiled by DSNTEJ71, DSNTEJ73 and DSNTEJ75. The problem is I don't have a C/C++ compiler. Could anyone send me the...
2
1758
by: brad | last post by:
Hi, I'm new to this group, and recently downloaded the MS Express package for C/C++. I tried to install and run some of the sample programs, and get a peculiar error. ------ Skipped Build:...
1
3702
by: comteck | last post by:
Does anybody know where I might find some sample database programs for ms access? I consider myself to be quite proficient at access. I'd like to maybe use my knowledge to do a little bit of free...
0
1189
by: Ken Gallagher | last post by:
Hi, all I started learning C++ a little while ago (mostly for curiiosity, as we're having a slow period at work and I find it kind of fascinating), and I read a little while ago that there were...
0
1624
by: pmp | last post by:
http://www.itworld2.com here you will see lot of sample C/C++ programs (source code)from basic to advance
0
1331
by: msmithuk | last post by:
Hi, I am looking for the DSNTEP2 sample applications in DSN810.SDSNSAMP referred to in the DB2 UDB for z/OS Version 8 Application Programming and SQL Guide (SC18-7415) (see link below for...
4
2550
by: ramprakashjava | last post by:
hi, i am new to struts framework so pls ref me link to download strurts sample programs Thanks in Advance ...
0
7202
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
7086
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
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7332
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...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
382
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.