Thread: Help!Help!I must finish my assignment today!!

  1. #1
    Compiling
    Join Date
    Jun 2003
    Posts
    69

    Arrow Help!Help!I must finish my assignment today!!


    My assignment must be submitted tommorow, but there are still some problems during compile........Anybody can help me??

    The project is about a ticket information system. If you give the start city and the destination, then the system will give back a serial number. Then if you want to check the ticket information, you can enter the serial number and get it. The personal information of the traveller will be stored in a tree data type (ADT type).

    This is the main programme

  2. #2
    Compiling
    Join Date
    Jun 2003
    Posts
    69

    Continued

    the implementations

  3. #3
    Compiling
    Join Date
    Jun 2003
    Posts
    69

    continued....

    the fatal errors

  4. #4
    Compiling
    Join Date
    Jun 2003
    Posts
    69

    continued.......

    the header file of the tree.

  5. #5
    Compiling
    Join Date
    Jun 2003
    Posts
    69

    The problems

    when i compile it
    the information showed:
    38¡A39¡A40 ,73,74,75¡Gdereferencing pointer to incomplete type

  6. #6
    Registered User
    Join Date
    Jul 2002
    Posts
    913
    you forgot some files.

    in void create(SearchTree T, int num) you use alot of gets, use fgets. im not sure if the compiler minds all those newlines but i do...

    in int check(char cityi[], char tmp[]) you have
    return 1;
    break;
    why use that break if that function is over right after the return 1?

    while (status != 1);
    the ';' should be a { so it actually does something.

    it doesnt look that bad, im still not sure if it will compile. try the other files. or maybe something isnt extern-ed.

  7. #7
    Registered User
    Join Date
    Jul 2002
    Posts
    913
    im guesing you did something like "char *ptr;" and set it equal to a int. the pointer needs to know what type its pointung to, i scew that up a couple times.

  8. #8
    Registered User
    Join Date
    Jul 2002
    Posts
    913
    i just noticed, why did you make more threads just to upload the files? you could of just held select.

  9. #9
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Originally posted by mart_man00

    while (status != 1);
    the ';' should be a { so it actually does something.
    No! You should study the do-while loop.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  10. #10
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    All your threads have been merged by me.

    If you want to reply, click "Post Reply" dont start new thread

  11. #11
    Compiling
    Join Date
    Jun 2003
    Posts
    69

    Would you please figure out the problem

    Code:
    #include "tree.h"
    #include <stdio.h>
    #include <string.h>
    #include "fatal.h"
    
    void
    getinfo(const char sn[], SearchTree T)
    {
      Position P;
      char city[21][10] = {"Beijing", "Chengdu", "Chongqing", "Changsha", "Changchun", "Dalian", "Fuzhou", "Guiyang", "Guiling", "Hangzhou", "Haikou", "Harbin", "Hefei", "Jinan", "Kunmin", "Lasa", "Nanjing", "Shanghai", "Shenyang", "Xiamen", "Xian"};
      char citycd[21][10] = {"PEK", "CTU", "CKG", "CSX", "CGQ", "DLC", "FOC", "KWE", "KWL", "HGH", "HAK", "HRB", "HFE", "TNA", "KMG", "LXA", "NKG", "SHA", "SHE", "XMN", "XIY"};
      char tmp1[2], tmp2[2], cityf[15], cityt[15];
      int num[6], i = 0, status1, status2;
      sscanf(sn, "%2d%2d%2d%2d%2d%2d%d", num[0], num[1], num[2], num[3], num[4], num[5], num[6]);
      do
        {
          tmp1[i] = (char) num[i];
          tmp2[i] = (char) num[i+3];
          i++;
        } while (i <= 2);
      i = 0;
      do
        {
          status1 = strcmp(tmp1, citycd[i]);
          i++;
        } while (status1 != 0);
      strcpy(cityf, city[i]);
      i = 0;
      do
        {
          status2 = strcmp(tmp1, citycd[i]);
          i++;
        } while (status2 != 0);
      strcpy(cityt, city[i]);
      P = Find(num[6], T);
      printf("From:%s\n", cityf);
      printf("To:%s\n", cityt);
    
    
    
      Here->       printf("Name:%s\n", P->Information->name);
      Here->       printf("Personal ID:%s\n", P->Information->id);
      Here->       printf("Nationality:%s\n", P->Information->nal);
    } 
    
    
    
    
    
    void
    getserial(const char cityfc[], const char citytc[], char sn[], int i)
    {
      int array1[2], array2[2], counter = 0;
      while (counter <= 2)
        {
          array1[counter] = (int) cityfc[counter];
          array2[counter] = (int) citytc[counter];
          counter++;	
        }
      sprintf(sn, "%d%d%d%d%d%d%d", array1[0], array1[1], array1[2], array2[0], array2[1], array2[2], i); 
    }
    
    void
    create(SearchTree T, int num)
    {
      Position P;
      char na[15], in[20], nn[15];
      printf("Please enter you name:");
      gets(na);
      printf("Please enter your personal ID number:");
      gets(in);
      printf("Please enter your nationality:");
      get(nn);
      Insert(num, T);
      P = Find(num, T);
      
    
      Here->        strcpy(P->Information->name, na);
      Here->        strcpy(P->Information->id, in);
      Here->        strcpy(P->Information->nal, nn);
    }
    
    int
    check(char cityi[], char tmp[])
    {
      int i = 0;
      char city[21][10] = {"Beijing", "Chengdu", "Chongqing", "Changsha", "Changchun", "Dalian", "Fuzhou", "Guiyang", "Guiling", "Hangzhou", "Haikou", "Harbin", "Hefei", "Jinan", "Kunmin", "Lasa", "Nanjing", "Shanghai", "Shenyang", "Xiamen", "Xian"};
      char citycd[21][10] = {"PEK", "CTU", "CKG", "CSX", "CGQ", "DLC", "FOC", "KWE", "KWL", "HGH", "HAK", "HRB", "HFE", "TNA", "KMG", "LXA", "NKG", "SHA", "SHE", "XMN", "XIY"};
      while (i < 21)
        {
          if (strcmp(cityi, city[i]) == 1)
    	{
    	  strcpy(tmp, citycd[i]);	
    	  return 1;
    	  break;
    	}
        }
      return 0;
    }
    
    int
    main(void)
    {
      SearchTree T1, T2;
      int sel, status = 0, i = 0, n = 0, num, innum, m = 1;
      char cityf[15], cityt[15], sn[15], cityfc[3], citytc[3], insn[15];
      do
        {
          printf("Welcome to the Ticket System!!\n");
          printf("1.Tickets sale\n");
          printf("2.Tickets check\n");
          printf("3.Exit\n");
          printf("Please chose the funtion you want:");
          scanf("%d", &sel);
          i++;
          if (sel == 1)
    	{
    	  do
    	    {
    	      printf("Please meet two or three segment toger eg. type Bei Jing as Beijing\n");
    	      printf("Please enter the city you want to set off:");
    	      gets(cityf);
    	      status = check(cityf, cityfc);
    	    } while (status != 1);
    	  do
    	    {
    	      printf("Please enter your destination:");
    	      gets(cityt);
    	      status = check(cityt, citytc);
    	    } while (status != 1);
    	  create(T1, i);
    	  getserial(cityfc, citytc, sn, i);
    	  sscanf(sn, "%d", &num);
    	  Insert(num, T2);
    	  printf("Your ticket serial number:%s\n", sn);
    	}
          if (sel == 2)
    	{
    	  printf("Please enter your ticket serial number:");
    	  scanf("%d", &innum);
    	  if (Find(innum, T2) == NULL)
    	    printf("Not Found!!");
    	  else
    	    {
    	      sprintf(insn, "%d", innum);
    	      getinfo(insn, T1);
    	    }
    	}
          if (sel == 3)
    	return(0);
        } while (m == 1);
      return(0);
    }

  12. #12
    Compiling
    Join Date
    Jun 2003
    Posts
    69

    Sorry

    Excuse me, how can I merge them together??

  13. #13
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793

    Re: Sorry

    Originally posted by NightWalker
    Excuse me, how can I merge them together??
    You cant...only another mod or I can do it.

    But in future, if you click Post Reply at the bottom of the last reply, all your posts will appear in the same thread.

  14. #14
    Compiling
    Join Date
    Jun 2003
    Posts
    69

    Lightbulb A few questions

    Very sorry to trouble you, but I think this structure
    Code:
    struct TreeNode
    {
      ElementType Element;
      Info Information;
      SearchTree  Left;
      SearchTree  Right;
    };
    is available, because these tree.c and tree.h I just copied from my textbook. I changed my programme as you said, but the compiler gives the same information as before:
    dereferencing pointer to incomplete type, I really don't know why.
    I use gcc compiler. What's the differences between fgets() and gets()? Thanks

  15. #15
    Compiling
    Join Date
    Jun 2003
    Posts
    69

    Question

    If move the structure declaration to the header file, how can I do that?
    Code:
    struct TreeNode
    {
      ElementType Element;
      Info Information;
      SearchTree  Left;
      SearchTree  Right;
    };

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu
    By Krush in forum C Programming
    Replies: 17
    Last Post: 09-01-2009, 02:34 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Help with a pretty big C++ assignment
    By wakestudent988 in forum C++ Programming
    Replies: 1
    Last Post: 10-30-2006, 09:46 PM
  4. Replies: 1
    Last Post: 10-27-2006, 01:21 PM
  5. 3x syntax errors :S, Help a student finalise an assignment
    By Chickenhawk in forum C Programming
    Replies: 14
    Last Post: 07-27-2006, 05:14 AM