>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.

Aia commented: Thanks for example. -Aia +1

Not to mention that his very own example is still unsafe!

>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.

Thanks for the response. And the examples....!!!!

My pleasure. :)

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

>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.

void main()
	float a,b,c;
	char sign,answer;
		  printf("Enter your choice of operator\n");
		  printf("+ for addition\n");
		  printf("- for subtraction\n");
		  printf("* for multiplication\n");
		  printf("/ for division\n");
		  printf("\nEnter two numbers\n");
		  scanf("%f %f",&a,&b);

			case '+':
				printf("The addition is %f\n",c);
			case '-': c=a-b;
			printf("The subtraction is %f\n",c);
			case '*': c=a*b;
			printf("The product is %f\n",c);
			case '/': c=a/b;
			 printf("The division is %f\n",c);
	 printf("Do you want to continue?(y or no)\n");


dude use this above code...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.