Undefined Symbol problem

This is a discussion on Undefined Symbol problem within the C Programming forums, part of the General Programming Boards category; Hi, I am working on a C program and I got the following function: Code: int printCount(char* fileName) { struct ...

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    23

    Undefined Symbol problem

    Hi, I am working on a C program and I got the following function:

    Code:
    int printCount(char* fileName)
    {
            struct Node* current;
            current = head;
            int unique = 0;
            int total = 0;
    
            printf("filename: %s\n\n", fileName);
            printf("COUNT | WORD\n");
            printf("------+------------------\n");
            while (current)
            {
                    unique +=1;
                    total +=current->count;
                    
                    printf("%5d | %s\n", current->count, current->word);
                    current = current->next;
            }
            printf("\n\n");
            printf("Number of Unique words found in %s is %d\n", fileName,
                   unique);
            printf("Total number of words in %s is %d\n", fileName, total);
    }
    I am compiling this code with the SUN cc compiler and it gives me the following errors on these lines:

    ' int unique = 0;'
    syntax error before or at: int

    'unique +=1;'
    undefined symbol: unique

    'total +=current->count;'
    undefined symbol: total

    'printf("Number of Unique words found in %s is %d\n", fileName,
    unique);'
    undefined symbol: unique

    'printf("Total number of words in %s is %d\n", fileName, total);'
    undefined symbol: total

    When I compile this program with the Unix gcc compiler it doesn't give me any errors, but as soon as I compile it with the cc compiler it throws me those "undefined symbol" errors. Does anyone know why?

    Thank you.

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Could it have anything to do with the fact that you don't declare those variables before you assign something to current?

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Code:
    current = head;
    Where has head come from? I'm assuming it's a global var...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. undefined symbol error during linnk time of library
    By quickNitin in forum C++ Programming
    Replies: 7
    Last Post: 09-01-2006, 11:06 AM
  2. Strange/false errors
    By Ganoosh in forum Windows Programming
    Replies: 8
    Last Post: 10-20-2005, 05:54 PM
  3. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  4. Undefined symbol 'stdprn'
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 07-03-2002, 03:05 PM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 10:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21