Thread: Undefined reference to 'Printf' ????

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    5

    Undefined reference to 'Printf' ????

    I am writing a program for my C programming class that is supposed to have basic ATM functions, but the problem is when I compile I get an error message saying "Undefined reference to 'Printf'." I have checked my printf statements and cannot find the problem. If anyone could help me out it would be much appreciated. Thanks

    Code:
    #include <stdio.h>
    
    
    #define SCREEN_HEIGHT 80    // Number of newlines to print out
    #define MAXLINE 100         // Maximum user input characters
    
    
    // Function prototypes
    void displayMenu(void);
    float checkBalance(int acctNum);
    int getAccountIndex(int acctNum);
    int transferFunds(int acct1, int acct2,float amt);
    int withdrawCash(int acctNum, int amt);
    int getline(char s[], int lim);
    void printError(char errNo);
    
    
    // Global List of account numbers
    int accountList[] =   {1234,   5289,    8744,  6912,  3421,   9658,  1487,  1147,     5732};
    
    
    // Global List of corresponding balances for each account (in same order of account number above)
    float balanceList[] = {4798.32,19628.89,150.78,100.00,6742.00,874.05,543.91,578963.45,8943.12};
    
    
    int main()
    {
        int accountNumber;
        char line[MAXLINE];
        double atof(char []);
        int i;
        int c;
        char userInput;
    
    
        // Get the persons account number (like putting in a debit card)
        printf("Please enter your account number: ");
        getline(line,MAXLINE);
        accountNumber = atof(line);
    
    
        if (accountNumber != accountList[i])
            {
                printError(-12);
            }
        do
        {
            displayMenu();      // read menu option using getline and atof functions
            getline(line, MAXLINE);
            int menuOption = atof(line);
            switch(menuOption)
                {
                    case 1:
                        checkBalance(accountNumber);
                    break;
                    case 2:
                        printf("Please enter the Account Number to transfer to");
    
    
                        getline(line,MAXLINE);
                        int x = atof(line);
    
    
                        printf("How much would you like to transfer?");
    
    
                        getline(line,MAXLINE);
                        int y = atof(line);
    
    
                        float z = transferFunds(accountNumber, x, y);
                        if (z != 0)
                            printError(z);
                        break;
    
    
                    case 3:
                        Printf("How much would you like to Withdraw?");
    
    
                        getline(line, MAXLINE);
                        int a = atof(line);
    
    
                        float b = withdrawCash(x,y);
    
    
                        if (b < 0)
                            printError(a);
                        else
                            printf("Cash despensing complete!");
                        break;
    
    
                    default:
                        printf("Error");
                        break;
                }
    
    
    
    
    
    
        } while (userInput != 4);
    
    
        return 0;   // Assume successful completion of program if we made it here
    }
    
    
    /* displayMenu:  display the menu options */
    void displayMenu(void)
    {
        int j;
        char userInput;
        // Clear out the screen contents
        for(j=0;j<=SCREEN_HEIGHT;j++)
            printf("\n");
    
    
        // Print the Menu Options
    
    
            printf("1. Check Balance\n");
            printf("2. Transfer Funds\n");
            printf("3. Withdraw Cash\n");
            printf("4. Exit\n");
    }
    
    
    
    
    
    
    /* checkBalance:  return the balance of the specified account */
    float checkBalance(int acctNum)
    {
        int x;
        x = getAccountIndex(acctNum);
        return balanceList[x];
    }
    
    
    /* getAccountIndex:  get the array index for the specified account */
    int getAccountIndex(int acctNum)
    {
        int i;
        for (i=0; i< sizeof(accountList)/sizeof(int); i++)
            {
                if (acctNum == accountList[i]) // make sure account number is on the list
                    {
                        return i;
                    }
            }
        return -1;
    }
    
    
    /* transferFunds:  transfer funds from acct1 to acct2 in the amount of amt */
    int transferFunds(int acct1, int acct2, float amt)
    {
        int i;
        int x;
        int y;
        float newBalance1;
        float newBalance2;
    
    
        x = getAccountIndex(acct1); // get each of the account indices.
        y = getAccountIndex(acct2);
    
    
        if (acct1 < amt) // verify there is enough money in account
            return -11;
        if (acct2 != accountList[i]) // make sure the account exists
            return -12;
    
    
        newBalance1 = acct1 + amt;
        newBalance2 = acct2 - amt;
    
    
        return 0;
    
    
    }
    
    
    /* withdrawCash:  deduct amount from account and show message for dispensing */
    int withdrawCash(int acctNum, int amt)
    {
        int newBalance;
        int x;
    
    
        x = getAccountIndex(acctNum);
    
    
        if (acctNum < amt) // make sure the account has enough money in it
            return -11;
    
    
        // Debit the amount from the account and print dispensing cash
        newBalance = acctNum - amt;
        printf("\nDispensing Cash...\n");
    
    
        return 0;
    }
    
    
    /* atof: convert string s to double */
    double atof(char s[])
    {
        double val, power;
        int i, sign;
    
    
        for( i=0; isspace(s[i]); i++)   /* skip white space */
            ;
        sign = (s[i] == '-') ? -1 : 1;
    
    
        if( s[i] == '+' || s[i] == '-')
            i++;
        for( val=0.0; isdigit(s[i]);i++)
            val = 10.0 * val + (s[i]-'0');
        if( s[i] =='.')
            i++;
        for( power=1.0; isdigit(s[i]); i++)
        {
            val = 10.0 * val + (s[i]-'0');
            power *= 10.0;
        }
    
    
        return sign * val/power;
    }
    
    
    /* getline: get line into s, return length */
    int getline(char s[], int lim)
    {
        int c,i;
        i=0;
    
    
        while( --lim > 0 && (c=getchar()) != EOF && c!= '\n')
        {
            s[i++] = c;
        }
    
    
        if(c == '\n')
        {
            s[i++] = c;
        }
    
    
        s[i] = '\0';
    
    
        return i;
    }
    
    
    /* printError: print the corresponding error message */
    void printError(char errNo)
    {
        // Based on input, print appropriate error message
        switch(errNo)
        {
            case -11:   printf("I'm sorry, you do not enough money to handle this transfer.\n");
    
    
            case -12:   printf("I'm sorry, the account number you entered does not exist.\n");
    
    
            case -13:   printf("Menu Options INVALID\n");
    
    
            default:    // Print a generic error for anything else calling this function
                printf("ERROR\n");
                break;
        }
    }

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    Do you know how to search a text file for specific occurrences of a string?

    I ask only because almost every piece of software on my computer supports "case sensitive search".

    Soma

  3. #3
    Registered User
    Join Date
    Apr 2012
    Posts
    5
    Quote Originally Posted by phantomotap View Post
    O_o

    Do you know how to search a text file for specific occurrences of a string?

    I ask only because almost every piece of software on my computer supports "case sensitive search".

    Soma
    Please excuse my innocence to programming I started only two months ago, but how would searching for the string help my problem? I did in fact use the find function built into codeblocks to check all of the printf statements, but unfortunately I could not find the problem. Please elaborate if you have the time. Thank you.

  4. #4
    Registered User
    Join Date
    Apr 2012
    Posts
    5
    Quote Originally Posted by phantomotap View Post
    O_o

    Do you know how to search a text file for specific occurrences of a string?

    I ask only because almost every piece of software on my computer supports "case sensitive search".

    Soma
    wow ..... i did not match the search to the case ..... YIKES

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    58
    Quote Originally Posted by mwoelfel View Post
    Please excuse my innocence to programming I started only two months ago, but how would searching for the string help my problem? I did in fact use the find function built into codeblocks to check all of the printf statements, but unfortunately I could not find the problem. Please elaborate if you have the time. Thank you.
    Code:
                      case 3:
                                Printf("How much would you like to Withdraw?");
    C is case sensitive. Printf should be all lowercase letters.

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Hint: Most compilers will tell you the line number where the problem is, some will even allow you to double-click the error to go straight to the offending line.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. undefined reference to ...
    By DeletedUserAccount in forum C Programming
    Replies: 16
    Last Post: 01-28-2011, 02:27 PM
  2. Undefined reference?
    By Tirith in forum C Programming
    Replies: 8
    Last Post: 08-11-2009, 02:39 PM
  3. Undefined Reference to..
    By PatoAqp in forum C++ Programming
    Replies: 13
    Last Post: 06-11-2009, 09:36 PM
  4. undefined reference
    By B_Love in forum C++ Programming
    Replies: 6
    Last Post: 09-26-2005, 08:13 AM
  5. undefined reference
    By Axel in forum C Programming
    Replies: 16
    Last Post: 09-11-2005, 09:42 PM

Tags for this Thread