Follow us on Twitter!
It is never to LATE to become what you never WERE.
Friday, April 18, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 27
Guests Online: 25
Members Online: 2

Registered Members: 82825
Newest Member: bulmers
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

Compiler compatibility


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-03-09 17:35
Just a quick question about C...

Is bloodshed compatible with vista? Although I was originally going to learn Perl my friend convinced me to learn C and C++ first.

I'm getting some strange errors though.
take this code for example...

Code
#include <stdio.h>

int mult ( int x, int y );

int main()
{
  int x;
  int y;
 
  printf( "Please input two numbers to be multiplied: " );
  scanf( "%d", &x );
  scanf( "%d", &y );
  printf( "The product of your two numbers is %d\n", mult( x, y ) );
  getchar();
}

int mult (int x, int y)
{
  return x * y;
}





When I compile and run it, (which i have done seperately and combined) It gives the first printf. But when I put in two numbers spaced or not, the program just exits. Its been doing this for all of my simple programs thus far. Although I did input getchar(); for another program and the program half worked, but I dont want to have to do this for all my programs.

I should also mention that the code above is merely an example from a tutorial.
Should I just skim the C tutorial and move on to C++?
According to my friend, C is the backbone for other programming languages which is why he wanted me to learn it.


Author

RE: Compiler compatibility


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-03-09 17:53
No, its the same before I compile it, if it runs at all.

My friend is kind of an arrogant idiot, but he's my only live source of advice.

What's the exact syntax for running it from command prompt? Because everything I put does nothing.

I'm 80% sure that its vista, but I'll try on a different computer later to see if I get the same errors.


Author

RE: Compiler compatibility

spyware
Member



Posts: 4192
Location: The Netherlands
Joined: 14.04.07
Rank:
God
Warn Level: 90
Posted on 03-03-09 18:03
MoshBat wrote:
It really isn't.


It is, programming in assembly is plain stupid, and dealing with flip-flops is just crazy talk.

C, the backbone? I'll sign that petition.



img507.imageshack.us/img507/3580/spynewsig3il1.png
"The chowner of property." - Zeph
[small]
Widespread intellectual and moral docility may be convenient for leaders in the short term,
but it is suicidal for nations in the long term.
- Carl Sagan
“Since the grid is inescapable, what were the earlier lasers about? Does the corridor have a sense of humor?” - Ebert
[/s
http://bitsofspy.net
Author

RE: Compiler compatibility


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-03-09 18:06
I use Dev C++ on my laptop (which has vista on it) all the time so I don't think that is your problem.


Author

RE: Compiler compatibility


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-03-09 18:16
that's exactly what I'm using.
It works with both C and C++?


Author

RE: Compiler compatibility


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-03-09 18:19
sharline23 wrote:
that's exactly what I'm using.
It works with both C and C++?


I don't code in C on my laptop (or at all for that matter) but I don't see why C++ would work and C wouldn't.


Author

RE: Compiler compatibility


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-03-09 18:21
sharline23 wrote:
It works with both C and C++?

Well it damn well should, valid C code is generally valid C++ code. Which means that C code should compile fine in a C++ compiler.


Author

RE: Compiler compatibility


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-03-09 19:03
I finally figured it out.

For whatever reason the getchar() function wasn't working right so I ended up using system( "pause" ) and everything works perfectly.




Edited by on 04-03-09 03:31
Author

RE: Compiler compatibility


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-03-09 19:13
I will assume you are running the program directly from Dev-C++. If you were to run it directly from the command line (the executable image generated or not) you won't really have this issue, you will still see the output. Assuming you type the following at the prompt:

"50 10"

And hit enter, the program will do the following: Take 50 and toss it into your first variable, 10 into the next and then stop taking characters from the input stream. What does this mean? Well, you hit Enter so there is still another character in the input stream! "\n" to be exact.

If you were to run this from Dev-C++ the 'back box' will just disappear due to the fact, well, the program has printed what it needs to and the program is done. But you didn't get to see your output you say? Well, the "getChar()" call at the end, it ran just as you expected it to. It consumed the newline character! If you really wanted to be persistent, you can simply just use another "getChar()" at the end of your program.

Some other compilers would do something a bit different however, they will run your program followed by a "pause" command to 'cmd.' You can do the same in your program if you wish. Replace "getChar()" with 'system("pause");' NOTE: This is going to be OS dependant, but if it fixes the program for now, you can see other ways to address the issue as you learn.

This may or may not be the issue depending on how you invoke your program, but who knows, it might help. Good luck with your studies, pm if you need anything.


Author

RE: Compiler compatibility


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-03-09 22:54
Code

#include <iostream.h>

int mult (int , int); //Function Prototype
void main()
{
   int num1,num2;
   cout << "Please input two numbers to be multiplied: ";
   cin >> num1;
   cin >> num2;
   cout << "The product of your two numbers is: "<< mult( num1 , num2 ) << endl;
   cin.ignore(cin.rdbuf()->in_avail() + 1);
} //End of main()

int mult (int x, int y) //Function Defenition
{
   return x * y;
}





Well, that's how I implement this in C++... It is compiled using Microsoft Visual C++ 6.0.

This will solve the break problem:
Code
cin.ignore(cin.rdbuf()->in_avail() + 1);





Author

RE: Compiler compatibility

hellboundhackersok
Member



Posts: 353
Location:
Joined: 20.09.07
Rank:
Moderate
Warn Level: 95
Posted on 04-03-09 01:42
sharline23 wrote:
I finally figured it out.

For whatever reason the getchar() function wasn't working right so I ended up using system("pause"Wink and everything works perfectly.


cin.get();
cin.get();

will work just as well.


i.imgur.com/qBWHo0R.png
Author

RE: Compiler compatibility

richohealey
Member



Posts: 1022
Location: #!/usr/local/bin/python
Joined: 01.05.06
Rank:
Monster
Posted on 05-03-09 00:09
Urgh... system("pause"Wink ... how many times does this need to be said.

Calling the pause binary is stupid because:

1) It breaks on old NT systems
2) It breaks on unix systems
3) It breaks on broken win32 platforms.
4) It's an unneccesary waste of resources to do something trivial.


bitchohealey at hotmail dot com skype:richohealey www.psych0tik.net
Author

RE: conio.h??


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 30-03-09 15:53
Why not use getch()???
just include<conio.h>....and instead of getchar();
put getch();
getchar() inputs your line feed(its present in enter....ascii code 10) too...
and C is (at least acc. to me) the backbone of programming....and Richohealey is right..I think you know what the system command does..




Edited by on 30-03-09 16:00