Share
Explore BrainMass

Recognize Digit String Surrounded by Optional White Spaces

Char line [MAXLINE];
int error,;
do {
printf("Input a positive integer: ");
fgets(line, MAXLINE,stdin);
error=sscanf(line,"%d",&n) !=1II n<=0;
if(error)
printf("|nERROR:Do it again.n");
} while(error);

Solution Preview

I assume that you do it in C (so the code looks).

An example of how to modify the code to do what you request is given below.

In case you do it in Visual Studio, I also attach a whole VS6 project in the zip file (it can easily be modified for VS7 and VS8, if needed).
It is worth to look into it in any case, as some of the characters used in ...

$2.19