5. Write a program to automatically generate the telephone numbers.
The requirements are as follows:
Declare a character array to hold a 7-digit telephone number
•Accept the telephone number as a string. The first four digits is the department code and the
last three digits is the telephone number. (Example: If the telephone number is “1001001” then
“1001” is the department code and “001” is the telephone number)
•Write a function called as ‘fnGenerateTelNumber’ that accepts the telephone number string as
an argument and returns the next telephone number in the sequence. (Example : For the above
telephone number the function should return next telephone number in the sequence as
1001002)
•Use ‘atoi’ function to convert the given string to an integer. (The function ‘atoi’ accepts a
character array and returns the integer equivalent if the string contains only digits)
•Increment the telephone number and return it to the function ‘main’.
•Display the telephone number
.
#include <stdio.h>
int fnGenerateTelNumber(char cTelephone_Num);
int main()
{
int iReturn_Num;
char caTelephone_Num[7];
printf("Enter the Telephone Number");
scanf("%s",caTelephone_Num);
iReturn_Num=fnGenerateTelNumber(caTelephone_Num);
printf("\n%d",iReturn_Num);
getch();
return 0;
}
int fnGenerateTelNumber(char cTelephone_Num)
{
int iTelephone_Num=atoi(cTelephone_Num);
return(iTelephone_Num++);
}