I am writing a code which prompt user to enter her mobile number and in result..I code to display it's user SIM network according to some principles which I code but I don't understand whats wrong with my code.. It saves data in a text file...
// 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;
}