Program has stopped working?

Hi!

Do you have any idea why my program stops from working?
Any causes for it to stop working?
Can you show us the source code?
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

int main() {
int a;
FILE * f_input;
FILE * f_output;
int b;

USER_MENU:
printf("[1] Encode File\n");
printf("[2] Decode File\n");
printf("[3] Exit\n");
printf("What do you want to do? ");
scanf("%d", &a);

switch(a) {
case 1:
//open file input.txt for reading
f_input = fopen("input.txt", "r");
if(f_input == NULL){
printf("\nFile input.txt was not found!!");
printf("\nFind the file and select again.\n");

printf("\n");
goto USER_MENU;
}

//f_input and f_output are not null then read characters
while((b = fgetc(f_input)) != EOF)
{
//writes the characters in the input.txt to output.txt
printf("%c", b);
}
//closes the files
fclose(f_input);
fclose(f_output);

printf("\n");
goto USER_MENU;
break;


Also, when I open the source code there was a tab opening that says "There was a problem sending the command to the program". Can anyone identify the cause of this?
up!

For one thing, you're using deprecated header files and functions. This is C code, not C++.
Also, get rid of those GOTO calls... I can't guarantee your safety in the programming community if you don't.
Last edited on
^
what do you mean deprecated header files?

Any why get rid of the GoTo calls?
what do you mean deprecated header files?
http://en.wikipedia.org/wiki/Deprecation

why get rid of the GoTo calls?
http://en.wikipedia.org/wiki/Spaghetti_code
thanks for informing me!

Are there substitutes for goto calls?

Any why get rid of the GoTo calls?


Because they're the sign of an amateur, not to mention completely unnecessary. You can easily replace them with a loop.
Can you give me an example how to substitute it with a loop?
goto calls are the only one's that needs to be substituted right\?
I do not know a lot about C so this may be wrong but It works for me so sorry if it does not work for you.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <cstdio>
#include <cstdlib>

int main ()
{
	bool Done = false;
	int A = 0 , B = 0;
	FILE * F_Input;
	FILE * F_Output;
	while (Done == false)
	{
		printf("[1] Encode File\n");
		printf("[2] Decode File\n");
		printf("[3] Exit\n");
		printf("What do you want to do? ");
		scanf ("%d" , &A);
		switch (A)
		{
			case 1:
				F_Input = fopen ("Input.txt" , "r");
				if (F_Input == NULL)
				{
					printf("\nFile input.txt was not found!!");
					printf("\nFind the file and select again.\n");
					printf ("\n");
				}
				else
				{
					do 
					{
						B = getc (F_Input);
						printf ("%c" , B);
					}
					while (B != EOF);
					printf ("\n");
				}
			break;
		}
	}
	return 0;
}
Just to help out, I thought I'd finish that loop for you with an exit condition:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <cstdio>
#include <cstdlib>

int main ()
{
  bool Done = false;
  int A = 0 , B = 0;
  FILE * F_Input;
  FILE * F_Output;
  while (Done == false)
  {
    printf("[1] Encode File\n");
    printf("[2] Decode File\n");
    printf("[3] Exit\n");
    printf("What do you want to do? ");
    scanf ("%d" , &A);
    switch (A)
    {
      case 1:
        F_Input = fopen ("Input.txt" , "r");
        if (F_Input == NULL)
        {
          printf("\nFile input.txt was not found!!");
          printf("\nFind the file and select again.\n");
          printf ("\n");
        }
        else
        {
          do 
          {
            B = getc (F_Input);
            printf ("%c" , B);
          }
          while (B != EOF);
          printf ("\n");
        }
      break;
      case 2:
        decode();
      break;
      case 3:
      default:
        Done = true;
      break;
    }
  }
  return 0;
}
Topic archived. No new replies allowed.