954,174 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

plzzz help me to convert string to integer

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

pawan_sharma777
Newbie Poster
20 posts since Jul 2010
Reputation Points: 9
Solved Threads: 0
 

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.

Ancient Dragon
Retired & Loving It
Team Colleague
30,046 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
 

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.

kings_mitra
Junior Poster
122 posts since May 2009
Reputation Points: 9
Solved Threads: 23
 

#include
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

pawan_sharma777
Newbie Poster
20 posts since Jul 2010
Reputation Points: 9
Solved Threads: 0
 

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.

Ancient Dragon
Retired & Loving It
Team Colleague
30,046 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: