i got a string E.g "12.67"
how do i convert it into a int so that
a= 12
b =67
any one can guide me along?
i got a string E.g "12.67"
how do i convert it into a int so that
a= 12
b =67
any one can guide me along?
string="12.67"
IFS="."
set -- $string
a=$1
b=$2
unset IFS
thanks but can help me convert to c++?
sorry, no, i didn't know you want it in c++
len = strlen(szInput);
i = atof ( szInput );
m = atol ( szInput );
temp =m;
while (temp != 0)
{
temp = temp/10;
cnt++;
}
ff = i-m;
len = len-cnt;
for (j=0;j<len-1;j++)
{
ff = ff *10;
}
n =(long)ff;
#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;
int main()
{
char p[] = "12.63";
char *pTok = strtok\(p, "."\);
int num1 = atoi\(pTok\);
cout << num1 << endl;
while\(pTok\)
\{
pTok = strtok\(NULL, "."\);
if\(pTok\)
\{
int num = atoi\(pTok\);
cout << num << endl;
\}
\}
return 0;
}
okie thanks all will go home and try it out thanks
istream& operator >>(istream &in,Account &ac)
{
string a,b,s;
char p[50];
fflush(stdin);
getline(in,s);
//cout<< s << endl;
p[] = s;
char *pTok = strtok(p, ".");
ac.a= atoi(pTok);
while(pTok)
{
pTok = strtok(NULL, ".");
if(pTok)
{
ac.b= atoi(pTok);
}
}
return 0;
return in;
}
i encounter compilation error when i try to put in to istream
anyone can advice me one this?
The easiest would be to use sscanf() and here's a way to do so in C...
int main() {
char s[] = "12.67";
int i, j;
sscanf(s, "%d.%d", &i, &j);
}