F
fool
Dear group,
Extract the integer value present in a given string. So I tried the
following:
int main(void)
{
int val;
char *data;
data = malloc(sizeof *data);
if(data)
scanf("%s",data);
while((*data++) != '\0')
{
/* Only the ascii char 0-9 is assigned to tmp (correct me if I am
wrong)*/
char tmp = data[0-9];
if(*data == tmp)
val = atoi(data);
printf("%d\n",val);
}
return 0;
}
It does not print what I wanted. can any one guide me to the solution.
please don't write the program for me. Thanks.
Extract the integer value present in a given string. So I tried the
following:
int main(void)
{
int val;
char *data;
data = malloc(sizeof *data);
if(data)
scanf("%s",data);
while((*data++) != '\0')
{
/* Only the ascii char 0-9 is assigned to tmp (correct me if I am
wrong)*/
char tmp = data[0-9];
if(*data == tmp)
val = atoi(data);
printf("%d\n",val);
}
return 0;
}
It does not print what I wanted. can any one guide me to the solution.
please don't write the program for me. Thanks.