I am trying to write a program that converts a string of numerals to integers. The program I have written gives me an invalid output. Any ideas what I have done wrong ?
//Defining what libraries should be included.
#include <stdio.h>
#include<math.h>
int strIntegerTmp(char *string, int collect);
int strInteger(char *string);
int main (void)
{
int collect;
char *string;
printf("Enter a string of integers: ");
scanf("%s", &string);
//length = strlen(string);
//printf("The integer entered is : %d\n", strInteger(collect));
printf("The integer entered is : %d\n", strInteger((char *) *string));
system("PAUSE");
return 0;
}
int strIntegerTmp(char *string, int collect)
{
if (!string || !*string || !isdigit(*string))
{
return collect;
}
else
return strIntegerTmp(string + 1, collect * 10 + (*string - '0'));
}
int strInteger(char *string)
{
return strIntegerTmp(string, 0);
}