1

>Here is the PROOF you need.....
I don't need proof that I'm right. I can't believe you actually thought that using gets in an extremely controlled environment would mean anything. By gets not being safe, here's my proof:

#include <stdio.h>

int main ( void )
{
  char pretest[20] = {0};
  char dummy[2];
  char posttest[20] = {0};

  int x;

  printf ( "Enter a number: " );
  fflush ( stdout );
  scanf ( "%d", &x );
  gets ( dummy );

  printf ( "pretest: \"%s\"\n", pretest );
  printf ( "posttest: \"%s\"\n", posttest );

  return 0;
}

Run that and type "123you're a moron". Overflowing a buffer is undefined, but with any luck you'll see something interesting.

Votes + Comments
Thanks for example. -Aia
0

>Not to mention that his very own example is still unsafe!
Yea, that's why I felt the need to post something that's obviously going to break so that his little sheltered world of "I control the input" is shattered and he might actually realize that gets is impossible to use safely.

0

Oh God! A lot of arguing and proving goin on here..Neways I figured it out guys.Thnx neways!

0

>A lot of arguing and proving goin on here..
Welcome to the world of programmers. Where success is measured by the ability to defend your ego.

0
#include<stdio.h>
#include<conio.h>
void main()
{
	float a,b,c;
	char sign,answer;
	clrscr();
	answer='y';
	do
	  {
		  printf("Enter your choice of operator\n");
		  printf("+ for addition\n");
		  printf("- for subtraction\n");
		  printf("* for multiplication\n");
		  printf("/ for division\n");
		  sign=getche();
		  printf("\nEnter two numbers\n");
		  scanf("%f %f",&a,&b);

		  //scanf("%c",&sign);
		  switch(sign)
		 {
			case '+':
				c=a+b;
				printf("The addition is %f\n",c);
				break;
			case '-': c=a-b;
			printf("The subtraction is %f\n",c);
			break;
			case '*': c=a*b;
			printf("The product is %f\n",c);
				break;
			case '/': c=a/b;
			 printf("The division is %f\n",c);
			 break;
		}
	 printf("Do you want to continue?(y or no)\n");
	 answer=getche();
	}
	while(answer!='n');
}

IwalkAlone......

dude use this above code...

Edited by Narue: Added code tags

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.