need help with program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cs1
    New Member
    • Sep 2007
    • 12

    need help with program

    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

    Code:
    #include <iostream>
    #include <cstring>
    using namespace std;
    
    
    struct pn {
    	char fn[25];
        char ln[25];
    	char pnbr[15];
          struct pn *next;
          };
    
    int main() 
    {
    	char t1[64], t2[64],t3[64];
          struct pn *start=NULL, *p1,*p2,p3;
    
          
    		  while(1){
    			  cin >> t1;
    			  if (strcmp(t1,"//")==0)break;
    			  cin >> t2 >> t3;
    
                p1 = new struct pn;
                if (p1 == NULL ) {
                      cout << "memory error\n";
                      return 1;
                      }
    			strcpy(p1 -> fn,t1);
               strcpy (p1 -> ln,t2);
    			strcpy(p1 -> pnbr,t3);
    			p1->next = start;
    				start = p1;          
                }
    
    		  while(1){
              cin >> t1;
    		  if ( strcmp(t1,"//")==0)break;
    		 
    		  cin >> t2;
    		  for (p1 = start; p1 != NULL; p1 = p1 -> next){
    		  if ( strcmp(t1,p1 ->fn)==0)
    			  (strcmp( t2,p1 ->ln)==0);
    				  cout << "found b" << p1->pnbr << endl;
          break;
    		  }
    		  
    
    		  {
    			  if (p1== NULL) cout << "not found";
    }
          
          
    
    
    		  
    		  return 0;
    	  
    			  }
    }


    so what my problem
    there is no output


    thanks
  • oler1s
    Recognized Expert Contributor
    • Aug 2007
    • 671

    #2
    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.

    Comment

    • cs1
      New Member
      • Sep 2007
      • 12

      #3
      thanks
      so all my code is wrong!!!!!!!!!! !!!!!!!1

      Comment

      • Shashi Sadasivan
        Recognized Expert Top Contributor
        • Aug 2007
        • 1435

        #4
        hi,
        when does this code come out of the loop?
        [CODE=cpp]
        while(1){
        cin >> t1;
        if (strcmp(t1,"//")==0)break ;
        cin >> t2 >> t3;

        p1 = new struct pn;
        if (p1 == NULL ) {
        cout << "memory error\n";
        return 1;
        }
        strcpy(p1 -> fn,t1);
        strcpy (p1 -> ln,t2);
        strcpy(p1 -> pnbr,t3);
        p1->next = start;
        start = p1;
        }[/CODE]

        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
        Last edited by Shashi Sadasivan; Nov 16 '07, 04:36 AM. Reason: is it pointer hell?

        Comment

        • cs1
          New Member
          • Sep 2007
          • 12

          #5
          ok
          can i just know what the output ganna be
          (just the output, i dont want the code)))
          thanks again

          Comment

          • Shashi Sadasivan
            Recognized Expert Top Contributor
            • Aug 2007
            • 1435

            #6
            if you have written the code yourself, have you tried compiling it?

            Comment

            • cs1
              New Member
              • Sep 2007
              • 12

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

              Comment

              • Ganon11
                Recognized Expert Specialist
                • Oct 2006
                • 3651

                #8
                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.

                Comment

                • cs1
                  New Member
                  • Sep 2007
                  • 12

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

                  Comment

                  • oler1s
                    Recognized Expert Contributor
                    • Aug 2007
                    • 671

                    #10
                    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...

                    Comment

                    • cs1
                      New Member
                      • Sep 2007
                      • 12

                      #11
                      thank you so much I'm working on it now.

                      Comment

                      Working...