August 4th, 2013, 03:14 PM
-
Questions about C
I'm fairly new to C. I've dabbled in C++ and Java, and I have a course in C this fall so I am trying to grasp the basics
I'm playing around with trying to display basically "hello world" and I keep getting a warning "Source code not compiled" when I run it. I feel as if it might be something with DevC++ but I saved it as a C file, not C++. Any ideas? I'm definately compiling it with success, just can't run it. I even googled a hello world example and it didn't help at all.
Code:
/* This is cool comment that I made */
int main()
{
printf("press enter to continue...\n");
system("pause");
return 0;
}
Last edited by Skipt; August 4th, 2013 at 03:21 PM.
"Quality of responses may vary. I reserve the right to change my mind for any reason what-so-ever without admitting I was wrong. I'd prefer to change your mind however, it's easier on my ego". - jwdonahue
"so no-one has actually bothered to post an original quote ? what's wrong with making up your own?"
- marnixR
August 4th, 2013, 04:11 PM
-
I also use Dev compiler.
printf("Hello World");
Or
puts("hello world");
Show your entire code.
And the other code you posted also works.
August 4th, 2013, 04:15 PM
-
I'm definately compiling it with success, just can't run it.
Are you sure?
What include files are you including? There should be at least two.
Jim
August 4th, 2013, 04:16 PM
-
Originally Posted by jimblumberg
Are you sure?
What include files are you including? There should be at least two.
Jim
I ran his code without any include fles and it still compiled. We use the same compiler.
Maybe the window closes immediately after running the prog?
If yes then :
getch(); <------
return 0;
>Works??
August 4th, 2013, 04:26 PM
-
Ive tried getch() and system("PAUSE");
I'm downloading Visual C++ from microsoft now and seeing if that helps. I tried downloading the regular bloodshed dev C++ version but the links were down so I downloaded the beta. Maybe it's some kind of bug, but google searches says this is nothing new. Let's see if this new editor works
Also, that was my entire code....it's just basically a hello world program....
"Quality of responses may vary. I reserve the right to change my mind for any reason what-so-ever without admitting I was wrong. I'd prefer to change your mind however, it's easier on my ego". - jwdonahue
"so no-one has actually bothered to post an original quote ? what's wrong with making up your own?"
- marnixR
August 4th, 2013, 04:29 PM
-
Originally Posted by jimblumberg
Are you sure?
What include files are you including? There should be at least two.
Jim
Why should there be at least two?
"Quality of responses may vary. I reserve the right to change my mind for any reason what-so-ever without admitting I was wrong. I'd prefer to change your mind however, it's easier on my ego". - jwdonahue
"so no-one has actually bothered to post an original quote ? what's wrong with making up your own?"
- marnixR
August 4th, 2013, 04:30 PM
-
Originally Posted by Skipt
Ive tried getch() and system("PAUSE");
I'm downloading Visual C++ from microsoft now and seeing if that helps. I tried downloading the regular bloodshed dev C++ version but the links were down so I downloaded the beta. Maybe it's some kind of bug, but google searches says this is nothing new. Let's see if this new editor works
Also, that was my entire code....it's just basically a hello world program....
:confused: lol
Well, try typing #include<stdio.h> at the top, should always work.
Code:
#include<stdio.h>
int main()
{
printf("hello world");
getch();
return 0;
}
August 4th, 2013, 04:37 PM
-
I've tried that. Right now I'm assuming it's a compiler error so I'm downloading Microsoft Visual C++ 2012 and gonna see how that works.
"Quality of responses may vary. I reserve the right to change my mind for any reason what-so-ever without admitting I was wrong. I'd prefer to change your mind however, it's easier on my ego". - jwdonahue
"so no-one has actually bothered to post an original quote ? what's wrong with making up your own?"
- marnixR
August 4th, 2013, 04:53 PM
-
You need <stdio.h> to use printf(). And you need <stdlib.h> to use the system() call.
Here are the compiler error messages I get when I try to compile your code:
/main.c||In function ‘main’:|
/main.c|6|error: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]|
/main.c|6|warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]|
/main.c|7|error: implicit declaration of function ‘system’ [-Wimplicit-function-declaration]|
Perhaps you need to increase your compiler warning level and insure you don't ignore any warnings or errors.
Jim
August 4th, 2013, 05:03 PM
-
I'm still getting error of source file not compiled
Code:
#include <stdlib.h>
#include <stdio.h>
int main()
{
printf("hello");
return 0;
}
Do i need to download something else? All I did was go to the website and download the beta. it's supposed to include mingw so that can't be it.
"Quality of responses may vary. I reserve the right to change my mind for any reason what-so-ever without admitting I was wrong. I'd prefer to change your mind however, it's easier on my ego". - jwdonahue
"so no-one has actually bothered to post an original quote ? what's wrong with making up your own?"
- marnixR
August 4th, 2013, 05:24 PM
-
What are your compile errors?
Did you create a project?
Perhaps you could post a screen shot of your compiler in action?
Jim
August 4th, 2013, 05:28 PM
-
Ok after googling, it seems it was a pathing error.
http://learntogeek.com/miscellaneous/solved-source-file-not-compiled-error-in-dev-cpp/
I did what he said, and now it won't let me compile. It says ‘Aborted(program collect2)’
Since the people on DevC++ didn't keep up to date with this program, you think it is just because I'm using Windows 8? If so, what alternative program should I use to code in?
"Quality of responses may vary. I reserve the right to change my mind for any reason what-so-ever without admitting I was wrong. I'd prefer to change your mind however, it's easier on my ego". - jwdonahue
"so no-one has actually bothered to post an original quote ? what's wrong with making up your own?"
- marnixR
August 4th, 2013, 05:32 PM
-
Originally Posted by Skipt
Why should there be at least two?
You are using two library functions which are prototyped in two different header files: printf in stdio.h and system in stdlib.h (I think, or maybe in dos.h; Read The Manual (RTFM!) for system(), which will tell you which header file you need to #include).
Actually, that's exactly the same as in C++, with which you claim to already have some experience. For that matter, if you know C++, then you already know C, since C++ is largely a super-set of C. Though most C++ books won't tell you about C-style strings nor about any kind of I/O except for iostreams.
As for your original problem, it looks like something went wrong with the installation of Dev-C++.
August 4th, 2013, 05:37 PM
-
Oh yea, I knew that, I thought he meant actual files that I wrote myself. Off the top of my head, I thought those were called libraries, oh well.
And yeah, it has been quite a few years since I've done much with it. I've already noticed its very similar. Right now I'm trying to figure out a workaround by installing it in windows 7 compatibility mode. I'll keep you all updated
edit: just read this on the site
"System : Windows 95/98/NT/2000/XP"
-_-
Last edited by Skipt; August 4th, 2013 at 05:45 PM.
"Quality of responses may vary. I reserve the right to change my mind for any reason what-so-ever without admitting I was wrong. I'd prefer to change your mind however, it's easier on my ego". - jwdonahue
"so no-one has actually bothered to post an original quote ? what's wrong with making up your own?"
- marnixR
August 4th, 2013, 05:51 PM
-
...okay running in XP compatibility didn't work. I'm out of ideas
"Quality of responses may vary. I reserve the right to change my mind for any reason what-so-ever without admitting I was wrong. I'd prefer to change your mind however, it's easier on my ego". - jwdonahue
"so no-one has actually bothered to post an original quote ? what's wrong with making up your own?"
- marnixR