Ad:
 
  • C Discussion Thread
  • Marked Solved
  • Views: 200
  • C RSS
Similar Threads
Jul 19th, 2010
0

plzzz help me to convert string to integer

Expand Post »
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++);
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pawan_sharma777 is offline Offline
10 posts
since Jul 2010
Jul 20th, 2010
0

Re: plzzz help me to convert string to integer

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.
Last edited by Ancient Dragon; Jul 20th, 2010 at 12:14 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 4864
Solved Threads: 1836
Still Learning
Ancient Dragon is offline Offline
18,371 posts
since Aug 2005
Jul 20th, 2010
0

Re: plzzz help me to convert string to integer

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.
Reputation Points: 7
Solved Threads: 21
Junior Poster
kings_mitra is offline Offline
109 posts
since May 2009
Jul 20th, 2010
0

i modify it but its not working properly please help........

#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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pawan_sharma777 is offline Offline
10 posts
since Jul 2010
Jul 20th, 2010
0

Re: plzzz help me to convert string to integer

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 4864
Solved Threads: 1836
Still Learning
Ancient Dragon is offline Offline
18,371 posts
since Aug 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Display Array Items Problem
Next Thread in C Forum Timeline: How do I find the next 6 byte aligned address





About Us | Contact Us | Advertise | Acceptable Use Policy
Build Custom RSS Feed


Follow us on Twitter


© 2010 DaniWeb® LLC