Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

C Language


  • Please log in to reply
13 replies to this topic

#1 JUICYboy

JUICYboy

  • Members
  • 537 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Anaheim, Ca
  • Local time:05:01 AM

Posted 11 November 2012 - 11:42 AM

Hello

I am learning the basics in C. I am fresh cheese B) and don't know what im doing wrong after careful research and following instructions.

I am learning how to output "Hello World" into Cmd box (Black box)

I carefully follow tutorials here:

BUT-----> I get a couple errors

1. The other day my errors was: Cant run program or can't compile dialogue box. (Should of taken a picture)

2. Then today it was: the #include <stdio.h> file could not be found saying: (No such directory) all do I went into the libraries folder and saw the file.

3. At the time of writting this: I get no errors BUT: The CMD (Black Box) does not come up???? Is there some small detail Im missing?

Can I run this on a Mac?

I don't know what Im doing wrong. All I want is to execute the black box with "Hello World" That would help me achieve a lot. I know its like level 0 but I got to start somewhere.

Thanks for your help :wink:

Edited by JUICYboy, 11 November 2012 - 11:45 AM.


BC AdBot (Login to Remove)

 


#2 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:02:01 AM

Posted 12 November 2012 - 09:26 AM

Forgive me, but I can't really watch the tutorial video at the moment. How did you install your compiler? What kind of compiler are you using? Are you doing this on a Windows PC or a Mac (given your Mac question)? What code did you attempt to use?

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#3 DarkSnake-Kobra

DarkSnake-Kobra

  • Members
  • 633 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Iowa, USA
  • Local time:04:01 AM

Posted 12 November 2012 - 02:49 PM

Hello

I am learning the basics in C. I am fresh cheese B) and don't know what im doing wrong after careful research and following instructions.

I am learning how to output "Hello World" into Cmd box (Black box)

I carefully follow tutorials here:

BUT-----> I get a couple errors

1. The other day my errors was: Cant run program or can't compile dialogue box. (Should of taken a picture)

2. Then today it was: the #include <stdio.h> file could not be found saying: (No such directory) all do I went into the libraries folder and saw the file.

3. At the time of writting this: I get no errors BUT: The CMD (Black Box) does not come up???? Is there some small detail Im missing?

Can I run this on a Mac?

I don't know what Im doing wrong. All I want is to execute the black box with "Hello World" That would help me achieve a lot. I know its like level 0 but I got to start somewhere.

Thanks for your help :wink:


Few things here.

1. What compiler are you using? Edit: - Looks like you are using Dev-C++. My advice is to drop it and use CodeBlocks (MinGW compiler bundle) as Dev-C++ hasn't been updated in years. Pretty much been abandoned.

2. You shouldn't need to use file extension when adding in an official library like stdio. It should be
#include <stdio>
. Now if you are adding in your own customer header then you would use something like
#include "customheader.h"
.

3. I'm not familiar with C, but you should post he full code here. Without the full code we really can't tell what you did wrong.

4. Yes and no. You'll need to recompile it under a Mac with a Mac based compiler. Every operating system uses their own native executable and/or other extensions that mark a file as a program so it should be in a Mac format whatever that is, but other then that the ISO Standards guarantee that a program will work regardless of the operating system providing that the C compiler conforms to the ISO Standards.

5. Also this is incorrect "My Compiler is not executing code on cmd" as a compiler does not execute code with cmd or any other program. A compiler just compiles the source code into object code that is then run by a linker that links the object code to one or more libraries and creates an executable program. The IDE however may include a debugger that executes the program which in turn uses the resources it needs including cmd.

Edited by DarkSnake-Kobra, 12 November 2012 - 02:55 PM.


#4 Romeo29

Romeo29

    Learning To Bleep


  • BC Advisor
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:04:01 AM

Posted 12 November 2012 - 09:36 PM

2. You shouldn't need to use file extension when adding in an official library like stdio. It should be

#include <stdio>
. Now if you are adding in your own customer header then you would use something like
#include "customheader.h"
.


I think this applies to C++ only. In C you have to specify ".h" for all kinds of header files.

#5 JUICYboy

JUICYboy
  • Topic Starter

  • Members
  • 537 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Anaheim, Ca
  • Local time:05:01 AM

Posted 12 November 2012 - 10:15 PM

Thanks for your help!

Here is answers:

1. I am using: Dev-c++ on Windows Xp

2. Here is the code{

#include<stdio.h>

main(){
printf("Hello World");
getchar();
}


}

3. My main goal is to learn C++ and Objective C. (Decided to start with the basics, do I need to?)

4. I will download the software and try to find some new Youtube tutorials

Thanks Ill start over again now.... I don't now much about programing... but im learning :busy:

Edited by JUICYboy, 12 November 2012 - 10:17 PM.


#6 Romeo29

Romeo29

    Learning To Bleep


  • BC Advisor
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:04:01 AM

Posted 13 November 2012 - 07:04 AM

3. My main goal is to learn C++ and Objective C. (Decided to start with the basics, do I need to?)


Then why are you wasting time in C? Go straight to C++.

#7 DarkSnake-Kobra

DarkSnake-Kobra

  • Members
  • 633 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Iowa, USA
  • Local time:04:01 AM

Posted 13 November 2012 - 02:48 PM



2. You shouldn't need to use file extension when adding in an official library like stdio. It should be

#include <stdio>
. Now if you are adding in your own customer header then you would use something like
#include "customheader.h"
.


I think this applies to C++ only. In C you have to specify ".h" for all kinds of header files.



Ah. I'm not familiar with C, but I do know some C++.

@JUICYboy I have to agree with Romeo29. C++ is more acceptable today since C is mostly used for building operating systems or system drivers and other very low level work. C++ should be efficient for whatever you need to do. :)

#8 Averyscript

Averyscript

  • Members
  • 4 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:USA
  • Local time:05:01 AM

Posted 14 April 2013 - 12:16 AM

Thanks for your help!

Here is answers:

1. I am using: Dev-c++ on Windows Xp

2. Here is the code{

#include<stdio.h>

main(){
printf("Hello World");
getchar();
}


}

3. My main goal is to learn C++ and Objective C. (Decided to start with the basics, do I need to?)

4. I will download the software and try to find some new Youtube tutorials

Thanks Ill start over again now.... I don't now much about programing... but im learning :busy:

 

 

If you are simply trying to print "Hello World," then you need to remove getchar();. That is used specifically to read a single character from the keyboard. The format is usually variable=getchar();.

 

Also, it should be: int main(). Not main().


Edited by Averyscript, 14 April 2013 - 12:25 AM.


#9 AceInfinity

AceInfinity

  • Members
  • 30 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Canada
  • Local time:02:01 AM

Posted 24 May 2013 - 10:10 PM

 

Thanks for your help!

Here is answers:

1. I am using: Dev-c++ on Windows Xp

2. Here is the code{

#include<stdio.h>

main(){
printf("Hello World");
getchar();
}


}

3. My main goal is to learn C++ and Objective C. (Decided to start with the basics, do I need to?)

4. I will download the software and try to find some new Youtube tutorials

Thanks Ill start over again now.... I don't now much about programing... but im learning :busy:

 

 

If you are simply trying to print "Hello World," then you need to remove getchar();. That is used specifically to read a single character from the keyboard. The format is usually variable=getchar();.

 

Also, it should be: int main(). Not main().

 

 

Actually, getchar() is most likely there as a measure to avoid the application terminating right away, so it should be kept there.

 

And once he uses int main(), I would expect to see a return 0; at the end as well. ;)


mvp.png
Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer


#10 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:02:01 AM

Posted 25 May 2013 - 01:26 AM

And once he uses int main(), I would expect to see a return 0; at the end as well. ;)

That's not actually true. main gets an exception to the usual rule that exiting a function without returning a value triggers undefined behavior.

See N3691 3.6.1 [basic.start.main]/5:

A return statement in main has the effect of leaving the main function (destroying any objects with automatic storage duration) and calling std::exit with the return value as the argument. If control reaches the end of main without encountering a return statement, the effect is that of executing

return 0;

Billy O'Neal
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#11 AceInfinity

AceInfinity

  • Members
  • 30 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Canada
  • Local time:02:01 AM

Posted 25 May 2013 - 01:28 AM

And once he uses int main(), I would expect to see a return 0; at the end as well. ;)

That's not actually true. main gets an exception to the usual rule that exiting a function without returning a value triggers undefined behavior.

See N3691 3.6.1 [basic.start.main]/5:

A return statement in main has the effect of leaving the main function (destroying any objects with automatic storage duration) and calling std::exit with the return value as the argument. If control reaches the end of main without encountering a return statement, the effect is that of executing

return 0;
Billy O'Neal
What's not true about it? It's good practice, I never said it required a return value, or I think you mis-read my post. It's not a good idea to leave it without a return value and expect it to do the work for you though. int datatype default is 0, but that should not mean that function main() should be neglected a return value by the programmer.

Edited by AceInfinity, 25 May 2013 - 01:39 AM.

mvp.png
Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer


#12 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:02:01 AM

Posted 25 May 2013 - 01:31 AM

I'm saying that it is guaranteed by the standard to work. I wouldn't say putting it there is good practice -- there's no technical reason to require it and it doesn't make the program any more or less readable either way. Therefore it is really a matter of opinion.

Personally for a program like this I think leaving it out is completely reasonable.

Billy O'Neal
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#13 annaharris

annaharris

  • Members
  • 12 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:02:31 PM

Posted 30 May 2013 - 08:06 AM

You can use a good tutorial for learning the basics of C. That would help you a lot.

 



#14 Romeo29

Romeo29

    Learning To Bleep


  • BC Advisor
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:04:01 AM

Posted 30 May 2013 - 07:03 PM

As per C99 standard, main() will return 0 even if you omit the return statement. But if you want to return a non-zero value then you can use return statement.

 

So both are legal - omit return or return an int.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users