What difference can you find between both Codes and why 1 of them is not working??

What difference can you find between both Codes and why 1 of them is not working??

This is a discussion on What difference can you find between both Codes and why 1 of them is not working?? within the C Programming forums, part of the General Programming Boards category; Hello,
this is my 1st post just wanted to know why is 1 of the below program not working and ...

Also tell me why is the declaration allowed in between. I mean in C variables can never be declared in between then how is the 1st code working??can anybody tell me the solution?i'll be very grateful to him..

In the first example, you are declaring a variable "n" that is local to the block inside the if and else branches of the if/else statements.

In the second case, you are declaring a new function-wide variable in the if-statement, then another with the same name in the else-branch. (and breaking the rules for standard C prior to C99, which states that varaibles must be declared at the beginning of the block).

Hello Salem,
#include <stdio.h> can also be written as #include "stdio.h"

Don't trust me??then try it for yourself!
and my question was something different, i think so or was it about header files?
and i know conio.h is not a standard C header file but when you write clrscr() to clear screen you have to include that file

Yes, you can include most files with either "file.h" or <file.h>.

The point Salem is trying to make is that you should only include "local" headers with "file.h", and you should use <file.h> for system include files, such as stdio.h. Essentially, it tells the reader where it's likely that this file will be [not the compiler, it just searches until it finds the right path].

A "local" header is produced as part of your current project - something that you would be likely to change at some time(s) during the code development.

A "system" header is something you didn't produce within the current project.

The same header file can be both at the same time:
Say for example you make your own 3D library functions, and then use those to produce a game, then the 3D library header files will probably count as system header files - because you are not changing those header files as part of the game development [1].

[1] You may of course fine bugs in your 3D library when you start using it for your game, and possibly fix that by modifying some header file that is part of the 3D library - but that should be done as part of the 3D library project bug fixing, and not as part of the game development.

Edit: As to books, problems and such, I don't know of a good book right now - I learned C about 15 years back, and I'm not sure the books I studied then are still in print, and I'm quite sure there are newer books - there is a "Books" subject in the forum tho, where people write good and bad things about different books.

For exercises, I don't know what sort of level to give those at, and you are probably better of with:
1. Scanning the forum here - there are new posts almost every day asking questions on "How can I write a program that does <something>" - try some of those exercises and see what you can do - just don't post it as a result.
2. Searching with Google for university classes online - there are quite a few with published exercises.