06-02-2012 12:15 PM
I've been working with c# for a long time now and have moved to obj-c to create an app for the playbook. Ive realised c# is much easier than objc when it comes to converting types.
Is there an acutal "String" type in obj-c? If not should I just use an array of chars?
Can someone explain to me how I would convert a float to a string/array of chars.
Can I use <string.h> in release (thining of the licence) since ive been using itoa to convert int to char array.
Any help would be greatly appreciated,
Solved! Go to Solution.
06-02-2012 03:13 PM - edited 06-02-2012 03:21 PM
Are you sure they support floats?
I have a float number. I need to print it to the console window to debug my app. I cant immediately put a float in to this char* so i need to convert the float to a string. How could i do this?
06-02-2012 03:32 PM
If you're printing to the console, printf() works. You just need to flush. The printf() documentation is more thorough in how it handles formatting, sprintf() and snprintf() work the same way, just to a string. How this helps. If not I suggest a C language intro book that will go into more detail on printf().
06-02-2012 04:32 PM
You can use printf to output floats. See http://www.cplusplus.com/reference/clibrary/cstdio
Also... you mean "C", not "Obj-C" right? Obj-C is what iOS uses and "C","C++","Obj-C" are three different things. Can I ask why you're not using C++ for your project, or even Qt? I feel both are easier to use for application development than C.
06-02-2012 05:02 PM
Yes sorry i mean C.
Well i started in C since i used the opengles 1.1 template. I just continued working on that cause ive never used opengl before. Ive only ever used directx. (from what ive been doing opengles 1.1 seems a heck of a lot more ”fixed“ than directx. But then maybe thats just mobile development).
Are there any librarys i need to include to use atof()?
Also what would the benefits be of using c++ instead of c? Would it overcomplicate it? Im a c# dev primarily so im used to having a lot of conversion calculations done for me lol.
Would you reccomend me to start again in c++?
I wouldnt mind cause the main reason im doing this is to learn a new language.
06-02-2012 09:43 PM
You might need to include a specific header for atof -- google will tell you which one. I don't know anything about C#. C++ has the standard library that can make certain things easier for you, especially when it comes to data structures for managing lists and so on. It also allows you to use an OOP design pattern.
Whether or not you should restart in C++ depends on what you're actually trying to design; if you're just playing around/learning with tutorials then switching is probably not worth it. If you're designing a large application that would benefit from OOP, switch over to C++.
Also as a side note, imo Qt is much friendlier than straight C or C++ with the stdlib. For instance with your string problem, Qt's QString class has a super easy to use "toFloat()" method: http://qt-project.org/doc/qt-4.8/QString.html.