Skip to content

Instantly share code, notes, and snippets.

@maz
Created October 9, 2011 20:34
Show Gist options
  • Save maz/1274128 to your computer and use it in GitHub Desktop.
Save maz/1274128 to your computer and use it in GitHub Desktop.
//NumberParser.h
@interface NumberParser : NSObject
{
char *str;
}
-(void)addDigit:(char)ch;
-(double)doubleValue;
@end
//NumberParser.m
#include <stdlib.h>
#include <string.h>
@implementation NumberParser
-(void)addDigit:(char)ch{
if(str){
size_t len=strlen(str);
str=realloc(str,len+2);
str[len]=ch;
str[len+1]='\0';
}else{
str=calloc(2,sizeof(char));
*str=ch;
}
}
-(double)doubleValue{
double num=atof(str);
free(str);
str=NULL;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment