nsstring - sprintf to objective c -


i have line of code:

sprintf ( label, "lon %s lat %s", lonstr, latstr ); 

which want replace one:

nsstring*label = [nsstring stringwithformat:@"%s %s", lonstr, latstr]; 

once replace warning stating unused variable 'label'. well, text supposed show no longer appears.

label declared this:

char label[256] = { 0 }; 

is there missing here?

hi again,

so after following advice , doing research solution. note tha variables 'label', 'labeltwo' , 'labelthree' c++ code had convert objective-c:

coordlabel.text = [nsstring stringwithformat:@"%@ %@", [nsstring stringwithcstring:label encoding:nsisolatin1stringencoding], [nsstring stringwithcstring:labeltwo encoding:nsisolatin1stringencoding]];

thank you

i fear missing basic understanding of objective-c , relationship c.

nsstring *label = [nsstring stringwithformat:@"%s %s", lonstr, latstr]; 

will create nsstring object pointed variable label.

nsstring , char * 2 different entities, former full-fledged objective-c object, whereas latter plain c string. don't expect nice happen if mistake 2 and, general suggestion, stick as possible nsstring objects.

now, problem, doing creating formatted nsstring miss step output content. can achieve using nslog function follows

nslog(@"%@", label); 

%@ format specifier used objective-c objects, nslog accept other specifier accepted (s)printf, in end can make shorter , write line:

nslog(@"%s %s", lonstr, latstr) 

bottom line deduce lonstr , latstr c strings, considering told above strongly suggest use nsstring instances instead.

edit

also

nsstring*label = [nsstring stringwithformat:@"%s %s", lonstr, latstr]; 

and

char label[256] = { 0 }; 

are both declarations of variable label (with 2 different types, joy!).

the compiler should (rightfully) give error redefinition of 'label', hardly believe code can compile far.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -