strncpy Function

To obtain a string containing just the characters belonging to a number, we simply copy out those characters from the full polish postfix string into a completely new string. The function for doing this is strncpy. It takes three parameters. The first is a target string, the second a source string and the third is the number of characters to copy across. Of course we already have the number of characters to copy, stored in our variable numLength, so this will be the third argument.

For the first argument, we must supply a blank string into which the relevant characters can be copied. For all of this, we add the following array and int variables to our calculate function:

char numString[20];
int currentNum;

Next we place the following lines inside our if construct:

strncpy(numString, strPointer, numLength);
numString[numLength] = '\0';
currentNum = atoi(numString);

The last of these lines is to properly terminate the new string we have created.