crashing with fgets?

Edit: derp, free() was suppose to be outside the while loop
Hi,

When I execute this from a case switch, it prints out "Would you like to continue (y/n)") two times and then crashes when I enter a letter. What's happening?

Is it because of fgets()?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
		static const char filename[] = "somefile.txt";	
		FILE *file = fopen(filename, "a+");
		

	 	char *name = malloc (256);

		while(name != "n" )
		{
		
			printf("Would you like to continue (y/n)");
			fgets(name, 256, stdin);
			free (name);
			

	}
Last edited on
On line 7: you compare two pointer which is in your case always true
Topic archived. No new replies allowed.