Originally Posted by
Dave_Sinkula
Perhaps this.
Code:
#include <stdio.h>
void MyFunc( char *text )
{
puts(text);
}
....
/* my output
1234
abc5
*/
Thanks so much . This works perfectly ...Here is what i needed to to (main function is given).
Code:
#include <stdio.h>
void MyFNatoi(char *, int *);
int main(void)
{
char numbers[5][10] = { "123456789", "0001234", "abc5xyz", "012a", "987654321" };
int i, value;
for(i=0; i<5; i++)
{
MyFNatoi(numbers[i], &value);
printf("array: '%s' int value: %d\n", numbers[i], value);
}
return (0);
}
void MyFNatoi(char *a, int *value)
{
int number;
int temp;
int i=0;
while(a[i]=='0')
i++;
do
{
temp=a[i]-'0';
if(temp>=0 && temp<10)
{
number=number*10+temp;
i++;
}
else
number=0;
}while( number!=0 && a[i]!='\0' );
*value=number;
}
Output:
array: '123456789' int value: 123456789
array: '0001234' int value: 1234
array: 'abc5xyz' int value: 0
array: '012a' int value: 0
array: '987654321' int value: 987654321
my task was just to write a function to convert character array to integer. Some more examples:
Code:
character array ('s'): integer pointer (*value):
----------------------------------------------------
"abc123" 0
"49" 49
"678abc" 0
"" 0
"889123" 889123
Once again, thanks so much . That was quick replies .