# Begginer with cocoa



## jpenguin (Feb 13, 2008)

I have a workin commandline program (C++) that I made for school, it has the user input a c-string the convverts it to lowercase, uppercase, or changes the case of each letter (QwErT to qWeRt).  Because my class us windoows, I had to write a GUI using MFC (or is it MFC?); I did that but because I use mac and hate windows I would like to write a GUI in Cocoa.Can I make an interface in Ccoa for this, how would I start to do this?  Even though I have an Objective-C book, I haven't had time to read it yet.


----------



## Mikuro (Feb 18, 2008)

You can integrate C++ into Objective-C/Cocoa apps. You might need to change the extensions of your ".m" files to ".mm", which will tell XCode to compile them as Objectice-C++ files. This might not be necessary if your C++ header files don't contain anything that's not standard C (e.g., no classes, no vectors, etc.).

Aside from that it will be just like making a regular Cocoa app. You'll hook up the buttons to the action of a custom object in Interface Builder, then call your C++ code from that action.

Check out http://www.cocoadev.com/index.pl?HowToProgramInOSX for some basic information.

And here's a tip I wish someone had given me when I was starting with Cocoa: try holding down the Control key and dragging between objects in Interface Builder.


----------



## jpenguin (Feb 18, 2008)

thanks for the reply











I use Opera, firefox, Camino, Sacfari  & iCab


----------



## jpenguin (Feb 18, 2008)

So, I ve gotten further, but I getting errors.  Once I figure out hou to ge the NSTextfeild conveerted to a cstring, the rest should be easier.  I am trying to get the lowercase function to work, then I'll do the rest.

If you have time, could you take a look at my code

The code for the commandline app is as fallows


```
#include <iostream>
#include <cctype>

using namespace std;
void upercase(char[]);
void lowercase(char[]);
void reversecase(char[]);
int main()
{
     char cstring[101];
     int ans;
     cout << "Enter a word or phrase up to 100 characters\n";
     cin.getline(cstring, 101);
     cout << "What do you want to do?\n";
     cout << "\n\tConvert to uperecase (1)\n\tConvert to lowercase(2)\n\tReverse the case of each letter (3)\n\n";
     cin >> ans;

     switch (ans)
     {
     case 1: upercase(cstring); break;
     case 2: lowercase(cstring); break;
     case 3: reversecase(cstring); break;
     }
     cout << cstring;
     cin.ignore();
     cin.get();
        return 0;
}
//---------------------------------------------------------------------------
void upercase(char word[])
{

     int length=strlen(word);
     for(int cnt=0; cnt<length; cnt++)
     {
     word[cnt]=toupper(word[cnt]);
     }
}
void lowercase(char word[])
{
     int length=strlen(word);
     for(int cnt=0; cnt<length; cnt++)
     {
     word[cnt]=tolower(word[cnt]);
     }
}
void reversecase(char word[])
{
     int length=strlen(word);
     for(int cnt=0; cnt<length; cnt++)
     {
     if(islower(word[cnt]))
       word[cnt]=toupper(word[cnt]);
     else if(isupper(word[cnt]))
       word[cnt]=tolower(word[cnt]);
     }
}
```


----------



## jpenguin (Feb 18, 2008)

Down to 3 errors
http://www.mediafire.com/?8smsbjrikdm


----------



## Mikuro (Feb 18, 2008)

There are a couple methods of NSString that return C strings. The simplest is -UTF8String. If you an encoding besides UTF8, you can use -cStringUsingEncodingNSStringEncoding*) instead.


----------



## jpenguin (Feb 19, 2008)

I guess I want UTF8, I  don't really know.  tHE ONLY REASON i NEED A CSTRINS S FOR FUNCTIONS LIKE STRLEN., TOUPPER & N TOLOWER.

SoRRy fOr the tOOgle cAPs

the dreaded capslock key strikes again!


----------



## jpenguin (Feb 19, 2008)

I convert it to a cstring in input.h, the cstring is named S.  My C++ funtion (in lower.mm) need to use this variable, but I can't figure out how to 'pass the variable'


----------



## Mikuro (Feb 24, 2008)

I'm not sure exactly what the problem is. Care to post some code?


----------

