ios - I keep getting three errors when trying to define a character array -


errors

instance variable declared

type name requires specifier or qualifier

expected ';' @ end of declaration list

i can't figure out why happening. please help!

here code:

viewcontroller.m

#import "evalviewcontroller.h"  @interface evalviewcontroller () {     digits[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; //errors: instance variable declared, type name requires specifier or qualifier, expected ';' @ end of declaration list       }  @end  @implementation evalviewcontroller   @synthesize terminal; @synthesize expression;   //add ieval prefix output -(void)writetoterminal:(nsstring *)string {     self.terminal.text = [nsstring stringwithformat:@"consolecalc> %@", string]; }   - (void)viewdidload {     [super viewdidload];     // additional setup after loading view, typically nib.      //define operation characters     self.add = '+';     self.sub = '-';     self.mult = '*';     self.div = '/';      //define digits compare digits in editableexpression  }  - (void)didreceivememorywarning {     [super didreceivememorywarning];     // dispose of resources can recreated. }   - (ibaction)evaluate:(uitextfield *)sender {     //set user input nsstring editableexpression     nsstring *editableexpression = self.expression.text;      //loop through new nsstring     (int i=0; < editableexpression.length; i++ ){         char charatposition = [editableexpression characteratindex:i];         //check if there + sign anywhere in expression , write "addition!" if there         if (charatposition == self.add){             if ([self checkfordigits]){                  [self writetoterminal:@"there digits in string!"];             }             else {                  [self writetoterminal:@"there no digits in string!"];              }           }          //check if there - sign anywhere in expression , write "subtraction!" if there         else if (charatposition == self.sub) {              [self writetoterminal:@"subtraction!"];           }          //check if there * sign anywhere in expression , write "multiplication!" if there         else if (charatposition == self.mult) {              [self writetoterminal:@"multiplication!"];         }          //check if there / sign anywhere in expression , write "division!" if there         else if (charatposition == self.div) {             [self writetoterminal: @"division!"];         }      }   }  //clear terminal  - (ibaction)clearterminal:(id)sender {      [self writetoterminal:@""];  }  - (bool)checkfordigits {     nsstring *editableexpression = self.expression.text;     (int = 0; < editableexpression.length; i++){         char charatposition = [editableexpression characteratindex:i];         (int c = 0; c < 10; c++ ){             if (charatposition == digits[c]){                 return true;             }             else {                 return false;             }         }        } }  @end 

viewcontroller.h

#import <uikit/uikit.h>  @interface evalviewcontroller : uiviewcontroller {      char digits[10];   }  //large text view @property (strong, nonatomic) iboutlet uitextview *terminal;  //user input @property (strong, nonatomic) iboutlet uitextfield *expression;  //evaluate expression - (ibaction)evaluate:(uitextfield *)sender;  - (ibaction)clearterminal:(id)sender;  //operation characters @property char add; @property char sub; @property char mult; @property char div;  //change information view  - (void)writetoterminal: (nsstring *) string;  - (bool)checkfordigits;     @end 

you declaring array incorrectly. delete header completely, , declare digits char array in implementation file (.m file). error should go away. also, assigning value incorrectly. creating char array of 10 elements, *assigning char array element @ 10th index, doesn't exist anyway. there multiple errors there. should bedigits = {...}notdigits[10] = {...}`.

if first start learning plain c , basics before moving objective-c, complicate more. see want create ios apps, make process easier, first need know basics of c well.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -