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++);
}

You posted the assignment, now tell us what question you have ???

>>int fnGenerateTelNumber(char cTelephone_Num)
That only declares a single character, not an array of characters. You have to
declare it like this: int fnGenerateTelNumber(char cTelephone_Num[]) or any of its other variants:
int fnGenerateTelNumber(char* cTelephone_Num)
int fnGenerateTelNumber(char cTelephone_Num[7])


When you declare the array in main() make sure you include space to hold the null-terminating character. If you want a 7-digit telephone number then the charcter array must be at least 8 bytes.

Yeah, you have done something with your assignment...now ask your doubts...!!!

Suggestions :
- Make the changes as AD told.
- Use fgets instead of scanf for accepting the telephone number as a srting.
- Don't use getch(), it is out of date. Use getchar() instead.
- Use code tags to include code segment in your future posts.

Everything else looks OK.

#include <stdio.h>
int fnGenerateTelNumber(char cTelephone_Num);
int main()
{
int iCount,iNum,iReturn_Num;
char caTelephone_Num[7];
printf("Enter the Telephone Number");
scanf("%s",caTelephone_Num);
printf("\nHow many Number you want to generate : ");
scanf("%d",&iNum);
for(iCount=0;iCount<iNum;iCount++)
{
iReturn_Num=fnGenerateTelNumber(caTelephone_Num);
printf("\n%d",iReturn_Num);
}
getchar();
return 0;
}
int fnGenerateTelNumber(char cTelephone_Num[])
{
int iTelephone_Num=atoi(cTelephone_Num);
return(iTelephone_Num++);
}
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

We know the requirements - you posted them in your original post.

Exactly what is it that you don't understand? If your compiler is producing errors, what are they? BTW the function prototype for fnTelephone_Num() is no longer consistent with the actual function. The parameters have to be identical.

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.