tab completion

Discussion in 'Mac Programming' started by jamesapp, Jun 3, 2008.

  1. jamesapp macrumors 6502a

    Joined:
    Mar 7, 2008
    #1
    james-collinss-macbook-pro:chap5 jamescollins$ gcc dcl.c -o dcl.out
    i686-apple-darwin9-gcc-4.0.1: dcl.c: No such file or directory
    i686-apple-darwin9-gcc-4.0.1: no input files

    why does computer not recognize dcl.c?
    i used tab completion on dcl.c and program compiled with following errors:

    james-collinss-macbook-pro:chap5 jamescollins$ gcc dcl.c\ -o dcl.out
    ld: warning in dcl.c , file is not of required architecture
    Undefined symbols:
    "_main", referenced from:
    start in crt1.10.5.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status


    here is my source file dcl.c

    Code:
    /* dcl: parse a declarator */
    void dcl(void)
    {
      int ns;
      
      for (ns = 0; gettoken() == '*'; )  /* count *'s */
           ns++;
      dirdcl();
      while (ns-- > 0)
          strcat(out, " pointer to");
    }
    
    /* dirdcl: parse a direct declarator */
    void dirdcl(void)
    {
      int type;
      
      if (tokentype == '(') {  /* ( dcl ) */
          dcl();
          if (tokentype != ')')
              printf("error: missing )\n");
      } else if (tokentype == NAME)  /* variable name */
          strcpy(name, token);
      else
           printf("error: expected name or (dcl)\n");
      while ((type=gettoken()) == PARENS || type == BRACKETS)
          if (type == PARENS)
              strcat(out, " function returning");
          else {
              strcat(out, " array");
              strcat(out,  token);
              strcat(out, " of");
           }
    }
    
    #include <stdio.h>
    #include <string.h>
    #include <ctype.h>
    
    #define MAXTOKEN 100
    
    enum { NAME, PARENS, BRACKETS };
    
    void dcl(void);
    void dircl(void);
    
    int gettoken(void);
    int tokentype;  /* type of last token */
    char token[MAXTOKEN];  /* last token string */
    char name[MAXTOKEN];  /* identifier name */
    char datatype[MAXTOKEN];  /* data type = char, int, etc. */
    char out[1000];  /* output string */
    
    main()  /* convert declaration to words */
    {
      while (gettoken() != EOF) {  /* 1st token on line */
          strcpy(datatype, token);  /* is the data type */
          out[0] = '\0';
          dcl();  /* parse rest of line */
          if (tokentype != '\n')
              printf("syntax error\n");
          printf("%s: %s %s\n", name, out, datatype);
      }
      return 0;
    }
    
    /* gettoken */
    int gettoken(void)  /* return next token */
    {
      int c, getch(void);
      void ungetch(int);
      char *p = token;
      
      while ((c = getch()) == ' ' || c == '\t')
          ;
      if (c == '(') {
          if  ((c = getch()) == ')') {
               strcpy(token, "()");
               return tokentype = PARENS;
           } else {
               ungetch(c);
               return tokentype = '(';
           }
      } else if (c == '[') {
          for (*p++ = c; (*p++ = getch()) != ']'; )
              ;
          *p = '\0';
          return tokentype = BRACKETS;
      } else if (isalpha(c)) {
          for (*p++ = c; isalnum(c = getch()); )
               *p++ = c;
          *p = '\0';
          ungetch(c);
          return tokentype = NAME;
      } else
          return tokentype = c;
    }
    
    #include <ctype.h>
    
    int getch(void);
    void ungetch(int);
    
    /* getop: get next operator or numeric operand */
    int getop(char s[])
    {
      int i, c;
      
      while ((s[0] = c = getch()) == ' ' || c == '\t')
          ;
      s[1] = '\0';
      if (!isdigit(c) && c != '.')
          return c;  /* not a number */
      i = 0;
      if (isdingit(c))  /* collect integer part */
          while (isdigit(s[++i] = c = getch()))
              ;
      if (c == '.')  /* collect fraction part */
          while (isdigit(s[++i] = c = getch()))
              ;
      s[i] = '\0';
      if (c != EOF)
          ungetch(c);
      return NUMBER;
    }
    
    just wondering why computer didn't recognize dcl.c, and why program didn't compile?
     
  2. fredfnord macrumors regular

    Joined:
    Sep 9, 2007
    #2
    Looks to me...

    ...like dcl.c has a space after the '.c' in the filename.

    As for the error message, well, try it without the space and see if it still happens.

    --fred
     
  3. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #3
    Your source code is very unorthodox. You should put includes at the top of the file along with defines and any global data (although I tend to put them in header files for simplicities sake).

    Have you just merged some source files into one?
     
  4. yeroen macrumors 6502a

    yeroen

    Joined:
    Mar 8, 2007
    Location:
    Cambridge, MA
    #4
    Your command line is wrong.

    Type this:

    gcc -g -o dlc dlc.c

    main() also needs a return type of int
     
  5. jamesapp thread starter macrumors 6502a

    Joined:
    Mar 7, 2008
    #5
    i had a space in the file name. i believe the space was causing problems, i also had other problems in the code.
     

Share This Page