// here is my code
#include <iostream>
#include <ctype.h>
#include <string.h>
#include <fstream>
#include <cstring>
#define MAX 15
using namespace std;
char fourdigOfnum(char *s1,char *s2) {
int i=0;
while(i<4)
{
s1[i]=s2[i];
++i;
}
s1[i]='\0';
}
int main() {
char num_dig[4],simCard[MAX];
char mobile_num[MAX];
ofstream file;
file.open("mobile.txt",ios::out);
cout<<"Enter a Mobile-Number : "; cin>>mobile_num;
if(mobile_num[0]==0||strlen(mobile_num)==11)
{
//num_dig=fourdigOfnum(str_num);
fourdigOfnum(num_dig,mobile_num);
if(num_dig[strlen(num_dig-1)]==0)
{
strncpy(simCard,"Jazz",sizeof(simCard));
}
else if(num_dig[strlen(num_dig-1)]==1)
{
strncpy(simCard,"Zong",sizeof(simCard));
}
else if(num_dig[strlen(num_dig-1)]==2)
{
strncpy(simCard,"Warid",sizeof(simCard));
}
else if(num_dig[strlen(num_dig-1)]==3)
{
strncpy(simCard,"Ufone",sizeof(simCard));
}
else if(num_dig[strlen(num_dig-1)]==4)
{
strncpy(simCard,"Telenor",sizeof(simCard));
}
} else {
cout<<"You entered a Invalid number "<<endl;
}
if(file.fail())
{
cout<<"Sorry File is failed to open "<<endl;
} else {
file<<"Your Mobile-Number is "<<mobile_num<<endl;
file<<"This is a "<<simCard<<" number "<<endl;
}
file.close();
system("pause");
return 0;
}
ICAgIC8vIGhlcmUgaXMgbXkgY29kZQogICAgI2luY2x1ZGUgPGlvc3RyZWFtPgogICAgI2luY2x1ZGUgPGN0eXBlLmg+CiAgICAjaW5jbHVkZSA8c3RyaW5nLmg+CiAgICAjaW5jbHVkZSA8ZnN0cmVhbT4KICAgICNpbmNsdWRlIDxjc3RyaW5nPgogICAgI2RlZmluZSBNQVggMTUKICAgIHVzaW5nIG5hbWVzcGFjZSBzdGQ7CiAgICBjaGFyIGZvdXJkaWdPZm51bShjaGFyICpzMSxjaGFyICpzMikgewogICAgICAgIGludCBpPTA7CiAgICAgICAgd2hpbGUoaTw0KQogICAgICAgIHsKICAgICAgICAgICAgczFbaV09czJbaV07CiAgICAgICAgICAgICsraTsKICAgICAgICB9CiAgICAgICAgczFbaV09J1wwJzsKICAgIH0KICAgIGludCBtYWluKCkgewogICAgICAgIGNoYXIgbnVtX2RpZ1s0XSxzaW1DYXJkW01BWF07CiAgICAgICAgY2hhciBtb2JpbGVfbnVtW01BWF07CiAgICAgICAgb2ZzdHJlYW0gZmlsZTsKICAgICAgICBmaWxlLm9wZW4oIm1vYmlsZS50eHQiLGlvczo6b3V0KTsKICAgICAgICBjb3V0PDwiRW50ZXIgYSBNb2JpbGUtTnVtYmVyIDogIjsgY2luPj5tb2JpbGVfbnVtOwogICAgICAgIGlmKG1vYmlsZV9udW1bMF09PTB8fHN0cmxlbihtb2JpbGVfbnVtKT09MTEpCiAgICAgICAgewogICAgICAgICAgICAvL251bV9kaWc9Zm91cmRpZ09mbnVtKHN0cl9udW0pOwogICAgICAgICAgICBmb3VyZGlnT2ZudW0obnVtX2RpZyxtb2JpbGVfbnVtKTsKICAgICAgICAgICAgaWYobnVtX2RpZ1tzdHJsZW4obnVtX2RpZy0xKV09PTApCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHN0cm5jcHkoc2ltQ2FyZCwiSmF6eiIsc2l6ZW9mKHNpbUNhcmQpKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlIGlmKG51bV9kaWdbc3RybGVuKG51bV9kaWctMSldPT0xKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBzdHJuY3B5KHNpbUNhcmQsIlpvbmciLHNpemVvZihzaW1DYXJkKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZSBpZihudW1fZGlnW3N0cmxlbihudW1fZGlnLTEpXT09MikKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgc3RybmNweShzaW1DYXJkLCJXYXJpZCIsc2l6ZW9mKHNpbUNhcmQpKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlIGlmKG51bV9kaWdbc3RybGVuKG51bV9kaWctMSldPT0zKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBzdHJuY3B5KHNpbUNhcmQsIlVmb25lIixzaXplb2Yoc2ltQ2FyZCkpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UgaWYobnVtX2RpZ1tzdHJsZW4obnVtX2RpZy0xKV09PTQpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHN0cm5jcHkoc2ltQ2FyZCwiVGVsZW5vciIsc2l6ZW9mKHNpbUNhcmQpKTsKICAgICAgICAgICAgfQogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGNvdXQ8PCJZb3UgZW50ZXJlZCBhIEludmFsaWQgbnVtYmVyICI8PGVuZGw7CiAgICAgICAgfSAKICAgICAgICBpZihmaWxlLmZhaWwoKSkKICAgICAgICB7CiAgICAgICAgICAgIGNvdXQ8PCJTb3JyeSBGaWxlIGlzIGZhaWxlZCB0byBvcGVuICI8PGVuZGw7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgZmlsZTw8IllvdXIgTW9iaWxlLU51bWJlciBpcyAiPDxtb2JpbGVfbnVtPDxlbmRsOwogICAgICAgICAgICBmaWxlPDwiVGhpcyBpcyBhICI8PHNpbUNhcmQ8PCIgbnVtYmVyICI8PGVuZGw7CiAgICAgICAgfQogICAgICAgIGZpbGUuY2xvc2UoKTsKICAgICAgICBzeXN0ZW0oInBhdXNlIik7CiAgICAgICAgcmV0dXJuIDA7CiAgICB9