Click here to Skip to main content
15,906,106 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
Problem Statement: Recognizing and Splitting the string.
You are required to write a program that takes a phone number as input from the user and stores it as a string value. The phone number will consist of country code, city code and actual 7-digit number separated by “-”. User can enter the phone number in any order. Your program should be able to recognize the country code, city code and 7-digit number and display it in the following format.
Country code - City code – 7-digit number


Detailed Description:

1. Take phone number as input from the user.
2. The number should be stored as a string value.
3. User can enter the phone number in any order for example 0092-333-1234567 or 333-0092-1234567 or 1234567-333-0092 etc.
4. Program should be able to recognize country code, city code and 7-digit number from the string and display it in the right sequence.


Sample Output 1
Enter the complete phone number : 0092-1234567-333

Country code is = 0092
City code is = 333
7-digit number is = 1234567
Phone number in correct sequence is = 0092-333-1234567



Sample Output 2
Enter the complete phone number : 1234567-321-0092

Country code is = 0092
City code is = 321
7-digit number is = 1234567
Phone number in correct sequence is = 0092-321-1234567


Sample Output 3
Enter the complete phone number : 300-0092-9876543

Country code is = 0092
City code is = 300
7-digit number is = 9876543
Phone number in correct sequence is = 0092-300-9876543



HINTS:
You can split the string into three parts and store each part as different string.
You should use strtok, strlen, and strcat functions for solving this assignment.

required to write a program that takes a phone number as input from the user and stores it as a string value. The phone number will consist of country code, city code and actual 7-digit number separated by “-”. User can enter the phone number in any order. Your program should be able to recognize the country code, city code and 7-digit number and display it in the following format.
Country code - City code – 7-digit number
Posted
Updated 18-May-10 8:02am
v2
Comments
Tarakeshwar Reddy 18-May-10 14:04pm    
What have you tried? No one is going to do your homework. Try implementing it and ask a specific question when you are not able to proceed.
Chris Maunder 18-May-10 14:16pm    
Reason for my vote of 1
You've got to be kidding us if you want us to do your homework for you.
William Winner 18-May-10 14:37pm    
Reason for my vote of 1
are you stuck on something? We can help if you're stuck on something, but if you want this done for you, try here: http://www.codeproject.com/script/Jobs/Edit.aspx
Johnny J. 18-May-10 15:03pm    
Reason for my vote of 1
What IS this? A do my homework for me to save my lazy ass forum? Not likely...

1 solution

Ok. Done it. Time taken: 4 minute, 3 seconds. Including time to load VS2008, start a new project, type, document, create test data and test/verify correctness.

Should I email it directly to your tutor, as well?
 
Share this answer
 
Comments
Johnny J. 18-May-10 15:01pm    
Let us know what grade you got, will you? :)
Sandeep Mewara 18-May-10 15:31pm    
He marked it as an answer accepted... did you really mailed it to him :P
Hope you didnt forget to cc his teacher ;)
OriginalGriff 18-May-10 15:41pm    
No I haven't sent it to him - I was waiting for his teachers' email... :big grin:
radix3 19-May-10 10:08am    
Mr.Griff i must say sir you have a good sense of humor, why didn't you mail his teacher :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900