Link to home
Start Free TrialLog in
Avatar of ambulance
ambulance

asked on

New to C: Looking for compiler

I am learning C from a book.  I am currently using the Visual C++ 6 (visual studio) compiler..however, approximately 50% of the programs are running.  

Do I need a new compiler?  

One other thought I had was that I am using the #include <stdio.h> statement..and it is rarely recognized.  If this is the problem..what do I need to do to correct it?

Thanks,
-A
Avatar of imladris
imladris
Flag of Canada image

I assume that your real problem is the 50% of the programs that are not running. Remember that 99% of the time the problem with a program not running lies with the programmer, not the compiler. There is, offhand, no reason to believe Visual C++ 6 is incapable of compiling the code.

stdio not being  recognized would certainly cause quite a lot of trouble. Exactly what error message do you get?

Avatar of ambulance
ambulance

ASKER

The only information the Error Message gives me is that 'stdio.h is not recognized'.  No more specific than that.  

Here is an example:  pretty simple, compiles okay, builds the .exe okay, but I go to run the .exe, get nothing.

Any ideas?  Am I doing something else wrong?

#include <stdio.h>

int x,y;

main()
{
      for (x = 0; x < 10; x++, printf ("\n"))
            for (y=0; y<10; y++)
                  printf("X");
                  
      return 0;
}
Go to Tools/Options/Directories. Select the appropriate 'Platform' then, under 'Show directories for:', select 'Include files'.

Make sure that the correct include directoy is listed.  It's usually <CompilerInstallPath>\include.

If that directory is not in the above list, add it.  If it is in the list, look in the directory to make sure stdio.h is there.
ambulance: How are you running the EXE file? If you just double-click it, or run it from the Visual Studio IDE, you might see a momentary flash as a console window opens, displays your Xs, then closes again--on a very fast system you might not even see this, so you'd think nothing happened. Try running a command prompt, changing to the directory the compiled program is in, and run it from there--since the window is already open you should see the results!
Visual C++ will recognize stdio.h only if the extension of the file you create is .c. By default it gives the extention .cpp and assumes you are coding in C++ and not in C, and will look for iostream.h and stuff. When creating the files, just explicitly mention the file name as .c, say you are creating 'foobar.exe', so make the program as 'foobar.c' and headers as 'foobar.h', then compile.

And about running the program, you will be better off if you open a DOS prompt, change to the directory where the executable is created, and run from command line.

Suvendra
When you run your that code a window will pop up but will then close almost immediatelty.
This is absolutely normal. To see the output of the result, you can:
1) put a getchar() statement just at the end of your program so that the window will not close but will once you hit the return key.
2) Run the program in dos.

As for the problem in including the stdio.h file, I think you should re-install VC.

hongjun
hongjun,

what information did you add that justifies "answering" the question?
I have checked out a few things.  I still don't have an answer yet...hopefully this will help narrow things down so I can figure out what I'm doing wrong.

1.  I did notice that some of the programs were running very fast. I was able to run them from DOS at a slower rate.  However, this only worked with the programs that were initially working.  

2.  All the C programs do have the extension .c.  However, I have not set any .h headings.  How do I know when I need to do that?

3.  I did go to Tools/Options/Directories.  The only platform available was Win32.  'Include Files' was already selected, but I was unable to locate the <CompilerInstallPath>\Include.  Where would I find that?  If that is supposed to be in the listbox still in Tools/Options/Directories, it isn't displaying.

4.  The getchar() statement didn't do anything different than what was already happening.  

Above, I posted a piece of code, that came from the text book, that won't run.  I have since come across a program that calls to #include <system.h> and that is causing a fatal compile error.  I am a VB programmer and am totally new to this syntax.  

Any additional help would be greatly appreciated.  I hope I'm not being totally blonde here.  You guys are helping a lot!

-A
What happened when you tried to run the program from a command prompt, like I suggested?
Well, about your point 2, you may need custom .h files, or Header files, if you need to pre declare the prototypes for functions you will be using across multiple C sub programs, going to give you one executable.

Can you also check the following. I guess you are doing it correctly, but when the program doesn't run on DOS, did you make 'console applications' for those - that is you are creating a new 'Console App' ?

Find out where stdio.h is installed in your system. For my convenience I am assuming that it is installed in C:\Visualdev\VC++\include. So change the code

#include <stdio.h>

to

#include "C:\Visualdev\VC++\include\stdio.h"

Check if the compiler can recognize that now. If it can't we need to check what other options can be there.

Suvendra
ASKER CERTIFIED SOLUTION
Avatar of sburck
sburck

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hello
i am c faculty & was shocked to hear that u r doing c under VC++; k i will try to explain u, see boss c was the first fundamental language & it has got some standards of ANSI called as ANSI C standards(here u will get use of stdio.h & all)& by using these standards C (specifically C) compilers r created which supports C programmes on same platforms. Then C++ is OOP language which can be called as superset of C & most of the compilers support C as well as C++ & the difference comes at the time of compilation i.e. if ur extension is ".c" like exampple.c then it will be compiled by C compilers but if it is ".cpp" then C++ compiler will take care of that. Difference is C++ comp. is little more strict about declaration where C is not as C++ is OOP & it requires everything to be declared before use. Now most of the C programmes can be compiled & linked under C++ comp. also but i said most of the----- there r always exception.
Now about VC++ -- people use to call it as system level programming language but frankly speaking its a tool -- better to say a very powerful tool for system level programming but only made for <<<<<windows>>>>> so it has got some platform specific code which is being generated by VC++ comp by internelly using C++ compiler just for windows so if u go for that u must be master in C & C++ to understand internal use of all these things. So frankly better u go for any C IDE like TC or Borland C & i think they r free now a days. If not just tell me & i will upload complete c for u & then u can get it downloaded! ok?
if u need any other further guidance then mail me & we can have chating so that if possible i can clear ur fundas online
my email - vinusa500@mailcity.com
Love Vinay
Whoa!  This is the last time I take a few days off of work!!  Thanks for all the responses.

I tried the Borland compiler and the 'miracle' compiler with not much more luck.  

But some luck nonetheless.  I am now up to a 75% run success rate.  I am happy about that.  I am assuming, that since I do have more running that the ones that don't have some typo in there that I missed the first few times around.

Now, I would like to give points to Sburk and CSuvendra.  They have been the most helpful.  I will give Sburk these points and post another questions to give points to CSuvendra.  Unless you know of a better way.

Thanks so much!!
-A
thankks a lot!