using gets() on operation file program

hey guys, i just made an operation program, this the part that confusing me.
1
2
3
4
5
6
7
8
9
10
11
12
 char a[1000];
        ofstream file1;
        file1.open("datamahasiswa.txt",ios::app);
        cout<<"inputkan nama: ";
        gets(a);
        file1<<endl;
        file1<<a;
        file1<<endl;
        getch();
        cout<<"file telah berhasil diinputkan."<<endl;
        cout<<"ketik '1' untuk kembali ke menu"<<endl;
        cout<<"ketik '0' untuk keluar "<<endl<<endl;

when i try to input the sentence using gets(a), the program seems like just jump over it and move to the next task cout<<"file telah berhasil diinputkan."<<endl; directly. can you help me please? oh, and this is my full program btw
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include <conio.h>
#include <math.h>
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <fstream>

using namespace std;

int input, alpha;
char str[10];

int cek(char str[])
{
    int i, panjang;
    panjang = strlen(str);
    for (i=0;i<panjang;i++)
    {
        if((i==0)&&(str[i]=='-'))
        i++;
        if(!isdigit(str[i]))
        {
            cout << "input harus berupa angka. silahkan inputkan kembali";
            return 0;
        }
    }
    return 1;
}

int main()
{
    masukan:
    cout<<"ketik '1' Menu Menambahkan Data Baru"<<endl;
    cout<<"ketik '2' Menu Menampilkan Data Terbaru"<<endl;
    cout<<"ketik '3' Menu Pencarian Data"<<endl;
    cout<<"ketik '4' Menu Menghapus Data"<< endl;
    cout<<"ketik '5' Menu Keluar"<<endl<<endl;
    do
    {
        cout<<"Silahkan Masukkan Pilihan: ";
        cin>>str;
    }while(!cek(str));
    input=atoi(str);

    if (input==1)
    {
        char a[1000];
        ofstream file1;
        file1.open("datamahasiswa.txt",ios::app);
        cout<<"inputkan nama: ";
        gets(a);
        file1<<endl;
        file1<<a;
        file1<<endl;
        getch();
        cout<<"file telah berhasil diinputkan."<<endl;
        cout<<"ketik '1' untuk kembali ke menu"<<endl;
        cout<<"ketik '0' untuk keluar "<<endl<<endl;
        do
        {
            cout<<"masukkan pilihan: ";
            cin>>str;
        }while(!cek(str));
        alpha=atoi(str);
        if(alpha == 1)
        {
            system("CLS");
            goto masukan;
        }
        else if(alpha == 0)
        {
            return 0;
        }
    }
    return 0;
}
Topic archived. No new replies allowed.