473,387 Members | 1,687 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

need help with program

12
here is the question
1. read in a first name, last name and telephone number
and store these in the list.
2. a search function that reads in a first name and last
name and searches the list for the name and prints
the phone number if found.


and the is what i did

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5.  
  6. struct pn {
  7.     char fn[25];
  8.     char ln[25];
  9.     char pnbr[15];
  10.       struct pn *next;
  11.       };
  12.  
  13. int main() 
  14. {
  15.     char t1[64], t2[64],t3[64];
  16.       struct pn *start=NULL, *p1,*p2,p3;
  17.  
  18.  
  19.           while(1){
  20.               cin >> t1;
  21.               if (strcmp(t1,"//")==0)break;
  22.               cin >> t2 >> t3;
  23.  
  24.             p1 = new struct pn;
  25.             if (p1 == NULL ) {
  26.                   cout << "memory error\n";
  27.                   return 1;
  28.                   }
  29.             strcpy(p1 -> fn,t1);
  30.            strcpy (p1 -> ln,t2);
  31.             strcpy(p1 -> pnbr,t3);
  32.             p1->next = start;
  33.                 start = p1;          
  34.             }
  35.  
  36.           while(1){
  37.           cin >> t1;
  38.           if ( strcmp(t1,"//")==0)break;
  39.  
  40.           cin >> t2;
  41.           for (p1 = start; p1 != NULL; p1 = p1 -> next){
  42.           if ( strcmp(t1,p1 ->fn)==0)
  43.               (strcmp( t2,p1 ->ln)==0);
  44.                   cout << "found b" << p1->pnbr << endl;
  45.       break;
  46.           }
  47.  
  48.  
  49.           {
  50.               if (p1== NULL) cout << "not found";
  51. }
  52.  
  53.  
  54.  
  55.  
  56.  
  57.           return 0;
  58.  
  59.               }
  60. }
  61.  


so what my problem
there is no output


thanks
Nov 16 '07 #1
10 1031
oler1s
671 Expert 512MB
You could not possibly have output. Your code is not compileable. Fix the syntax errors.

Fix your indentation. It's a mess. Poorly indented code means you can't read it properly, and you'll make mistakes in editing it.

Watch your struct syntax. This is C++, not C. Read a C++ book on struct syntax if you aren't sure.
Nov 16 '07 #2
cs1
12
thanks
so all my code is wrong!!!!!!!!!!!!!!!!!1
Nov 16 '07 #3
Shashi Sadasivan
1,435 Expert 1GB
hi,
when does this code come out of the loop?
Expand|Select|Wrap|Line Numbers
  1. while(1){
  2.               cin >> t1;
  3.               if (strcmp(t1,"//")==0)break;
  4.               cin >> t2 >> t3;
  5.  
  6.             p1 = new struct pn;
  7.             if (p1 == NULL ) {
  8.                   cout << "memory error\n";
  9.                   return 1;
  10.                   }
  11.             strcpy(p1 -> fn,t1);
  12.            strcpy (p1 -> ln,t2);
  13.             strcpy(p1 -> pnbr,t3);
  14.             p1->next = start;
  15.                 start = p1;          
  16.             }
Its been a while since i touched pointers, but dosent start always gets pointed to the newly created struct?
which means that when u create a new node, the previous one is lost as a memory leak and you have no access to it anymore?
please correct me if i am wrong
Nov 16 '07 #4
cs1
12
ok
can i just know what the output ganna be
(just the output, i dont want the code)))
thanks again
Nov 26 '07 #5
Shashi Sadasivan
1,435 Expert 1GB
if you have written the code yourself, have you tried compiling it?
Nov 27 '07 #6
cs1
12
yeah i tried but the there is nothing

i don't want the program to work i just want to know how the program output should be . that's it.

thanks
Nov 27 '07 #7
Ganon11
3,652 Expert 2GB
Well, if the program doesn't work, then the output will be incorrect.

My guess is, you are looking for a cheap way out of doing an assignment. As you should know from reading our Posting Guidelines, we don't give away solutions to problems without the user having tried.

If you want the output of this program, you will have to correctly write the program first. Now, we are more than willing to help you - if you are willing to do some work and not demand the solution from us.
Nov 27 '07 #8
cs1
12
Ganon11
I understand that but I didn't say I want the answer I said i want to know how the out put should be like.

thanks again
Nov 27 '07 #9
oler1s
671 Expert 512MB
There really doesn’t seem to be much to it. Then again, you’re the one with the question paper.

I would guess you have a menu system, someway of acknowledging or rejecting user input, and so on. It’s just simple console based output, so it’s not going to look like much more than ASCII...
Nov 27 '07 #10
cs1
12
thank you so much I'm working on it now.
Nov 27 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Spamtrap | last post by:
I only do occasional Perl programming and most things I write are short processes. I have something I'm working on that is scanning a text file with about 15 million lines and trying to extract...
2
by: aj902 | last post by:
Hello , I am trying to create a program where all detail, http://www.albany.edu/~csi333/projects.htm
13
by: vgame64 | last post by:
Hi, I have been struggling with writing a program for a few hours. The requirements are that: """You will be writing a program which will determine whether a date is valid in terms of days in that...
4
by: robinsand | last post by:
My apologies to those of you who are more advanced Visual C++ .NET programmers, but I am working on a project for an MBA course that is condensed into an eight-week schedule, and I need help...
16
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client...
8
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the sequence no and item type etc ...but i need only...
4
by: naknak4 | last post by:
Introduction This assignment requires you to develop solutions to the given problem using several different approaches (which actually involves using three different STL containers). You will...
6
by: naknak | last post by:
Introduction This assignment requires you to develop solutions to the given problem using several different approaches (which actually involves using three different STL containers). You will...
1
by: peterggmss | last post by:
This is a slot machine game, 2 forms. One is the actual game (frmMachine) and the other is in the background and randomizes the images shown on frmMachine. I need to make frmMachine wait for...
1
by: raghavshastri | last post by:
You are to write a C++ program to perform a statistical analysis of the blobs in an image. The image will be a grayscale image in PGM format for simplicity. Here is a sample PGM image with 10...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.