Originally Posted by
CommonTater
You should never use an output flush on an input buffer... so no fflush(stdin) is not going to work...
Since you don't seem prone to post your code and your explanation is clear as mud.. there's not much we can do to help you. Most often there are simple solutions but there is no one solution for every situation...
If you're referring to the problem with the trailing newline, most often the solution is simple...
Code:
scanf("%[^\n]", mystring);
// or
scanf ("%s %d", mystring, myint);
while(getchar() != '\n');
If it's something else... POST CODE... and lets see what we can do...
I'm not using strings, so I tried making for the
Code:
scanf("%[^\n]", mystring);
which didn't work (program froze) then I tried
Code:
while(getchar() != '\n');
which failed(froze) I assume because I entered a valid input so it kept looking for \n which didn't exist:
heres a segment of the code which is the issue:
Code:
void main_menu(int index)
{
int ch;
int input;
float inputTwo;
switch(index)
{
case 1:
printf("please enter new particle limit\n<default 2000> <min 50> <max 2000>\nnew limit: ");
scanf("%d%*c", &input);
if(input >= 50 && input <= 10000)
{
num_particles = 0;
particleLimit = input;
printf("success there now are: %d particles\n", particleLimit);
}
else
{printf("%d is not alloud\n", input);
}
break;
case 2:
printf("please enter new fountain spray radius\n<default 1> <min .3> <max 1>\nnew spray radius: ");
scanf("%f%*c", &inputTwo);
if(inputTwo >= 0.3 && inputTwo <= 1)
{
howClose = inputTwo;
printf("success spray radius now equals: %f\n", howClose);
}
else
{
printf("%f is not alloud\n", inputTwo);
}
break;
case 3:
if(evening == true)
{
evening = false;
}
else
{
evening = true;
}
break;
case 4:
break;
case 5:
printf("please enter new spawn rate(seconds)\n<default 0.01> <min 0.001> <no max>\nnew spawn rate: ");
scanf("%f%*c", &inputTwo);
if(inputTwo >=0.001)
{
spwnTime = inputTwo*1000;
printf("success, spawn rate now equals: 1 particle every %d milliseconds\n", spwnTime);
}
else
{
printf("that was too low\n");
}
break;
case 6:
printf("please enter new mass for particles\n<defaul 1> <min 1> <no max>\nnew mass: ");
scanf("%f%*c", &inputTwo);
if(inputTwo >= 1)
{
currentMass = inputTwo;
printf("success, new mass = %f\n", currentMass);
}
else
{
printf("failed, mass MUST be positive\n");
}
break;
case 7:
printf("please enter new size for particles\n<defaul 0.015> <min 0.001> <max 1>\nnew size: ");
scanf("%f%*c", &inputTwo);
if(inputTwo >= 0.001 && inputTwo <= 1)
{
currentSize = inputTwo;
printf("success, new size = %f\n", currentSize);
}
else
{
printf("%f is not acceptable\n", inputTwo);
}
break;
case 8:
crrntPrtclType++;
if(crrntPrtclType > 1)
{
crrntPrtclType = 0;
}
break;
case 9:
printf("please enter new definition for objects with definition settings\n<default 10> <min 3> <no max>\nnew definition: ");
scanf("%d%*c", &input);
{
if(input >= 3)
{
prtclDef = input;
printf("success, new definition: %d\n", prtclDef);
}
else
{
printf("definition can't be less than 3\n");
}
}
break;
case 10:
spurtType++;
if(spurtType>2)
{
spurtType = 0;
}
printf("%d\n", spurtType);
break;
case 11:
printf("please enter new fountain power\n<default 4> <min 2> <no max>\nnew fountain power: ");
scanf("%f%*c", &inputTwo);
if(inputTwo>=2)
{
fountaintSpeed = inputTwo;
printf("success, new fountain power: %f\n", fountaintSpeed);
}
else
{
printf("power must be greater than 2\n");
}
break;
case 12:
exitModual();
break;
}
}