#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
char getChar(char **p){
return *(*p)++;
}
void skipSpace(char **p){
while(isspace(getChar(p)));//skip space char
--(*p);//unget
}
char getSign(char **p){
if(**p=='+' || **p=='-') return *(*p)++;
return ' ';
}
void getNatural(char **p, char *buff){
while(isdigit(**p))
*buff++=*(*p)++;
*buff='\0';
}
void getFloatPart(char **p, char *buff){
char point;
point = getChar(p);
if(point != '.'){
*buff = '\0';
} else {
*buff++ = point;
getNatural(p, buff);
}
}
void separate_float(char **p, char *sign, char *int_part, char *float_part){
skipSpace(p);
*sign = getSign(p);
getNatural(p, int_part);
getFloatPart(p, float_part);
}
int main(){
char line[128]="S -51.235";
char *p = line;
char command;
char sign, int_part[32], float_part[32];
command = getChar(&p);
if(command == 'S'){
separate_float(&p, &sign, int_part, float_part);
printf("%c,%s,%s\n", sign, int_part, float_part);//-,51,.235
printf("%d %g\n", atoi(int_part), atof(float_part));//51 0.235
}
return 0;
}