Please help me to catch this error

S

santosh

Amali said:
I got what they pointed out.but in this project they are mostly
considering about only the documentation. And it is no enought to this
project what we learnt in the class. Now i need to learn more about c
programming.

What you want to do can be done with just the basics of C and a few
Standard library functions. The problem is that you're unwilling to
correct the errors and other ill-advised constructs in your code that
posters in this thread have repeatedly pointed out to you.

Your program, as it stands, is simply incorrect. If it appears to
work, be assured that it's only so by pure chance. At a minimum
correct the following:

1. Change the line 'void main(void)' to 'int main(void)' and place a
'return 0;' statement at the very end of the main function.

2. Remove all instances of 'fflush(stdin)'. It's undefined.

3. Replace all uses of gets(s) with fgets(s, SIZE_OF_S, stdin).

4. Check for end-of-file with the return value of the function you use
to read. It'll return EOF if end-of-file occurs.

5. Correct your use of fscanf. It keeps overwriting previous values.
Use an array instead of a single variable for holding the input.

If you don't know how to use any of the features I've listed above, or
how to correct your program, please ask, but simply posting the same
incorrect code again and again is not helping anyone.
 
L

Lew Pitcher

On Mar 12, 4:00 pm, (e-mail address removed) (Richard Bos) wrote: [snip]
Does your teacher know what he's doing? If so:
Automatic fail.
[snip]
Why it must int main. accoding to my knowladege it is not returning
any thing. Its only calling to another function.

main() returns an int value because that's how it is defined.

Very few C programs run as the sole activity of a computer. Those that
do are called "standalone" programs, and there are special rules
around the language features that are open to them.

The rest of the C program universe (a /much/ larger set of programs)
all run within the confines of some system (or systems) that arranges
for their execution and cleans up after they complete. Often, these
systems arrange subsequent processing based on whether or not the C
program accomplished it's task. Of course, this requires that the C
program be able to tell this larger environment whether it was
successful or not. That's what the int returned by main() is all
about.

The return value from main() provides this indicator of success or
failure. It can take one of three values (within the confines of the C
standard): EXIT_SUCCESS (which indicates that the C program succeeded
in it's task), EXIT_FAILURE (which indicates that the C program failed
in it's task), and 0 (which is interpreted as success, like
EXIT_SUCCESS). You will find EXIT_SUCCESS and EXIT_FAILURE defined in
the stdlib.h header.

Even in your (evidently) MSDOS environment, the environment can (and
frequently does) make decisions and take actions based on the success
or failure of the programs it initiates. Failure to return such an
indicator not only violates the C language standard, but endangers
your operating environment. If you do not return a value, there's no
telling what the environment will think happened, and it may make the
wrong decisions regarding futher processing.

So, besides the fact that you are required by the language to return a
value from main(), it is also a good idea to return a value from
main() no matter what your environment. If the value is unnecessary,
your environment will ignore it, but if the value /is/ necessary and
your program /does not/ return it, your environment may malfunction
and take the wrong actions.

HTH
 

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

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top