hi guys,
could you please help me with my C++ question
i have to do it until April 11.
i did it but i'm not sure if it's right
Here is my program question:
Write a function that takes a string and tries to turn it into a
positive integer value. If the string has any characters that are not digits then return -1, otherwise return the integer value of the string. For example, for the string "12345" return the int 12345. For the string "12a45" return -1. For the string "-23" return -1, since the dash character('-') is not a digit.
Here is the function declaration:
int stringToPositiveInt(char s[ ]);
This is what i did but i'm really confused about my program:
int stringToPositiveInt(char s[ ])
{
if (strcmp(s, "12345") == 0)
return s;
else if (strcmp(s, "12a45") == 0)
return -1;
else
return -1;
}
I would greatly appreciate for your help
my best regards
albina



LinkBack URL
About LinkBacks



) for the input "12345" and "12A45".
.