Mathcalculations with C or C++
By Tron at Fri, Jul 2 2010 11:32am |
Hi, I want to use my computer for high number calculations, but i am a double ZERO in programming. I had started to program on my old computer (windows) with c, but i think i need c++ if i want to use graphical signs, like sinus functions???
How can i program on Mac OS X version 10.5.8. (leopard)?
I am not able to use the Xcode, or lets better say i have no clue how it works!
Thanks to all who help me!
Tron




A brief user´s manual with
A brief user´s manual with how to set it up for c and c++ programing and how to actually run the compiler should work.
Thanks
Tron
Oh, i forgot. I changed something as well on the old-downloaded Xcode, so i don´t know if i ruined something? Where can i get an c and c++ compiler??
If you have Xcode installed
If you have Xcode installed you should already have a C/C++ compiler. Open up Terminal and type gcc or g++. If you see
i686-apple-darwin10-gcc-4.2.1: no input filesor
i686-apple-darwin10-g++-4.2.1: no input filesthen you can compile C/C++ files. For all the compiling flags look up the gcc manual online. If you want to compile a C++ file named main.cpp simply enter the following in Terminal (assuming you are in the folder containing main.cpp)
g++ main.cppyou can run the executable by typing
./a.outI hope that helps.
Jeff
Ok, thanks in the first
Ok, thanks in the first place for responding at all!
I am able to compile c/c++ files! (cause "i686-apple-darwin9-gcc-4.0.1: no input files" appears)
I typed " g++/Users/civoc/Desktop/xcode/cvaa/Aufg01.cpp"
got then
-bash: g++/Users/civoc/Desktop/xcode/cvaa/Aufg01.cpp: No such file or directory
changed the filename to only c, as i have it in my folder on .c
g++/Users/civoc/Desktop/xcode/cvaa/Aufg01.c
and got then
-bash: g++/Users/civoc/Desktop/xcode/cvaa/Aufg01.c: No such file or directory
I have in my Xcode folder an " Eclipse Platform" but i am not able to debug or compile the files!
I have here this plaintext in the Eclipse Platform:
#include
main() {
printf("\nDas Ergebnis von\n12 durch 4 ist %i.",3);
}
This is what i have used on my Windows2000 C++ Compiler (Dev-C++) !
The example is from a german c textbook, where the examples are also available in the internet!
If i Press Run in the Run-window a window appears which says "unable to launch - the selection cannot be launched, and there are no recent launches."
The same appears if i try to "debug" it (as well under the runbutton).
I have another example :
#include
main() {
printf("\nDieser Text\nenthaelt\nviele\nZeilenumbrueche");
}
which as well doesn´t run or isn´t able to debug!
Do i need to debug in order to compile? I did it on Dev-C++!
Thanks
Tron
Found the GCC online Manual. (understand not even half of it)
Will see to read that the further days!
Why don't you try something
Why don't you try something like Python first???
Learn the basics of programming with Python, then use the numerical libraries like scipy / numpy / matplotlib to calculate and plot your results. For things like linear algebra, Python / numpy is very close to to the performance of of compiled languages like C or Fortran, and you can run it interactively.
And for numerics, IMO, your a lot better off with modern fortran (Fortran 90,95,2003) then you are with C/C++ considering that the C family of languages don't even have 'true' support for multi-dimensional arrays. Fortran is a higher level language, so the language takes care of a lot of nonsense that you have to deal with in the C family.
With all due respect, but
With all due respect, but calling Fortran a higher level language than C++ is nonsense. "Higher-level" has nothing to do with "supports feature X", and also doesn't imply that the higher-level language is superior or better suited for a certain task. It simply designates the level of abstraction that is possible with the language.
Regarding matrix computations and multi-dimensional arrays: If dense matrices and vectors are all your code will ever need, I second that you are much better off with Fortran (or numpy, for that matter). However, that's as far as Fortran goes: Fortran does not natively support banded or sparse matrices, and does not let you choose the memory layout of its multi-dimensional arrays. All of this is supported in C++ (boost), but you pay for these features with a considerably steeper learning curve.
Easier options than C? Along
Easier options than C?
Along the same line of one of the comments about Python, something you may want to try is Octave (free Matlab-like programming language). It is very easy to learn (easier than C/C++/Fortran?)
You can download it at the following URL:
http://www.gnu.org/software/octave/
Cheers
Nico
www.volcanoloco.org
www.gns.cri.nz
Well i am a little familiar
Well i am a little familiar with C that is why i wanted to use C. I just can´t handle the macintosh!
I will have to work with machines (process engineering) which use C or C++.
And i don´t like to buy myself a windows computer because i am to retarded to use my mac in the proper way.
XCode is really really easy
XCode is really really easy to use.
If you really want to use C/C++ to learn, you really can not get much easier than XCode.
XCode is the IDE (Integrated Development Environment) for the Mac, this is the Visual Studio equivalent (personally, I think XCode is FAR FAR better then VS, but same sort of thing).
XCode installs either off the second OSX disc, or you can download it at:
http://developer.apple.com/technologies/xcode.html
There are TONS of XCode tutorials, just google "XCode Tutorial C++". Basically, it will automatically create a project for you complete with a c++ file you can start adding your code in. It will compile/debug all in one. It really can not get much simpler for C++ than XCode.
note that the C/C++ language is severely lacking when in comes to multi-dimensionall arrays, so you have to use a library like flens, or boost ublas, but these are down the road. First learn the basics of procedural programming / compiling / debugging.