Hi all! I have been given the task to modify the code below so that it can do subtraction, multiplaction and division, not just addition. Could someone help me with this and explain what the strncpy does? I'm so confused!!
// C Parsing Adder program
#include <stdio.h>
#include <string.h>
// the code starts here
void main()
{
// declare the variables
char user_input[100] , operand1str[100] , operand2str[100] ;
char * operator_address;
float operand1, operand2, result;
// get an addition from the user, as a string
puts ("Parsing Adder: Please Enter an Addition");
gets ( user_input);
// find the address of the operator (i.e. +) in the user's string
operator_address = strchr( user_input, '+' );
// extract the first operand (the one before the operator)
strncpy ( operand1str, user_input, operator_address - user_input );
// extract the second operand (the one after the operator)
strcpy ( operand2str, operator_address + 1 );
// convert the operands to float, perform the addition and print the result
sscanf ( operand1str , "%g", &operand1 ) ;
sscanf ( operand2str , "%g", &operand2 ) ;
result = operand1 + operand2 ;
printf ( "= %g\n", result ) ;
}