i have program C++ but i will convert to C
How to convert C++ to C?

    #include <iostream.h>
    #include <conio.h>
    struct mahasiswa
    {
    int nbi;
    char nama[50];
    char alamat[50];
    int telp;
    };
    void main()
    {
    int pilihan,pilihan1,T;
    menu:
    mahasiswa data[3];
    cout<<"Pilih Menu :"<<endl;
    cout<<"1.Input Biodata"<<endl;
    cout<<"2.Tampilakn Semua Data"<<endl;
    cout<<"3.Cari Biodata"<<endl;
    cout<<"4.Urutkan Berdasarkan NBI"<<endl;
    cout<<"Keluar"<<endl;
    cout<<"\n";
                    cout<<"Pilihan =";cin>>pilihan;
    clrscr();
    if(pilihan==1)
    {
    {
    cout<<"Inputkan Biodata 1"<<endl;
    cout<<"\n";
    cout<<"NBI=";cin>>data[0].nbi;
    cout<<"Nama=";cin>>data[0].nama;
    cout<<"Alamat=";cin>>data[0].alamat;
    cout<<"No.TeleponI=";cin>>data[0].telp;
    clrscr();
    cout<<"Inputkan Biodata 1"<<endl;
    cout<<"\n";
    cout<<"NBI=";cin>>data[1].nbi;
    cout<<"Nama=";cin>>data[1].nama;
    cout<<"Alamat=";cin>>data[1].alamat;
    cout<<"No.Telepon=";cin>>data[1].telp;
    }
    getch();
    clrscr();
    goto menu;
    }
    else if(pilihan==2)
    {
    {
    cout<<"Inputan Data1"<<endl;
    cout<<"\n";
    cout<<"NBI="<<data[0].nbi<<endl;
    cout<<"Nama="<<data[0].nama<<endl;
    cout<<"Alamat="<<data[0].alamat<<endl;
    cout<<"No.TeleponI="<<data[0].telp<<endl;
    cout<<"\n\n";
    cout<<"Inputan Data2"<<endl;
    cout<<"NBI="<<data[1].nbi<<endl;
    cout<<"Nama="<<data[1].nama<<endl;
    cout<<"Alamat="<<data[1].alamat<<endl;
    cout<<"No.TeleponI="<<data[1].telp<<endl;
    }
    getch();
    clrscr();
    goto menu;
    }
    else if(pilihan==3)
    {
    {
    cout<<"Cari Biodata??"<<endl;
    cout<<"Inputan ke Berapakah yg ingin anda cari??=";cin>>pilihan1;
    if(pilihan1==1)
    {
    cout<<"NBI="<<data[0].nbi<<endl;
    cout<<"Nama="<<data[0].nama<<endl;
    cout<<"Alamat="<<data[0].alamat<<endl;
    cout<<"No.Telpon="<<data[0].telp<<endl;
    }
    else if(pilihan1==2)
    {
    cout<<"NBI="<<data[1].nbi<<endl;
    cout<<"Nama="<<data[1].nama<<endl;
    cout<<"Alamat="<<data[1].alamat<<endl;
    cout<<"No.Telpon="<<data[1].telp<<endl;
    }
    }
    getch();
    clrscr();
    goto menu;
    }
    else if(pilihan==4)
    {
    {
    cout<<"Urutan Data Brdasarkan NBI"<<endl;
    T=data[0].nbi;
    if(T>data[1].nbi)
    {
    T=data[1].nbi;
    cout<<"NBI                                        ="<<T<<endl;
    cout<<"Nama                                    ="<<data[1].nama<<endl;
    cout<<"data                                       ="<<data[1].alamat<<endl;
    cout<<"No.telpon  ="<<data[1].telp<<endl;
    cout<<"\n";
    cout<<"NBI="<<data[0].nbi<<endl;
    cout<<"Nama="<<data[0].nama<<endl;
    cout<<"Alamat="<<data[0].alamat<<endl;
    cout<<"No.TeleponI="<<data[0].telp<<endl;
    }
    else
    {
    cout<<"NBI="<<data[0].nbi<<endl;
    cout<<"Nama="<<data[0].nama<<endl;
    cout<<"Alamat="<<data[0].alamat<<endl;
    cout<<"No.TeleponI="<<data[0].telp<<endl;
    cout<<"\n";
    cout<<"NBI="<<data[1].nbi<<endl;
    cout<<"Nama="<<data[1].nama<<endl;
    cout<<"Alamat="<<data[1].alamat<<endl;
    cout<<"No.Telpon="<<data[1].telp<<endl;
    }
     }
    getch();
    clrscr();
    goto menu;
    }
    else
    {
    goto exit;
    }
    exit:
    }





How to convert C++ to C??

help me please

Recommended Answers

All 6 Replies

That's an old dialect of C++ and doesn't use any difficult to convert features. You need to do three things:

  1. Change cin to scanf function calls.
  2. Change cout to printf function calls.
  3. Add a typedef to your structure so that the struct keyord isn't required:

    typedef struct mahasiswa
    {
    int nbi;
    char nama[50];
    char alamat[50];
    int telp;
    } mahasiswa;
    

For #3, as an alternative you can add the struct keyword to every declaration of the type:

struct mahasiswa data[3];

how about

clrscr();

?

Provided your compiler supports the non-standard conio library, it'll work between C and C++.

no, I want to try convert C++ to C

It's a C library, but also works for C++.

Or you could just write your own clrscr() function, it's not all that difficult, just a one line function.

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.