Errors calling function

This is a discussion on Errors calling function within the C Programming forums, part of the General Programming Boards category; When I compile, I get these errors: Code: 44 C:\Documents and Settings\xxxxx\My Documents\School\cis111\projects\d4test.c [Warning] passing arg 1 of `print_ssnum' makes ...

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    76

    Errors calling function

    When I compile, I get these errors:
    Code:
    44 C:\Documents and Settings\xxxxx\My Documents\School\cis111\projects\d4test.c [Warning] passing arg 1 of `print_ssnum' makes integer from pointer without a cast
    Code:
    44 C:\Documents and Settings\xxxxx\My Documents\School\cis111\projects\d4test.c invalid use of void expression
    I guess I dont see whats wrong with this code:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int change(char *before) {
         
         int after = 0;
         char *end;
    
         after = strtol(before, &end, 0);
         after = (after * 100) + strtol(end + 1, &end, 0);
         after = (after * 10000) + strtol(end + 1, &end, 0);
    
         return after;
    }
    
    void print_ssnum(int pc) {
      
         printf("%2d-%4d-%2d\n", pc / 1000000, pc / 10000, pc % 10000);
    }
    
    void main (void) {
    
         struct student {
              
             int grad_year;        /* members defined here */
             char ........n, *dob, name[40], curr[4];
         };
         
         struct student    s;
         struct student    *sp;
    
         s.grad_year = 2010;
         s.ssn = "142-76-6900";
         s.dob = "11/17/1975";
         s.name;
         s.curr;
              
         sp = malloc (512 * sizeof(struct student));        /* Allocate memory 50 times 4 bytes wide */
         strcpy(s.name, "Douglas W Van Allen");
         strcpy(s.curr, "CIS");
         *s.ssn = change(s.ssn);
         *s.dob = change(s.dob);
         printf("Cotents of s:\nName of Student = %s\nSocial Security Num = %d\nDate of Birth = %d\nCurriculum = %s\nGraduation year = %d\n", 
              s.name, print_ssnum(s.ssn), s.dob, s.curr, s.grad_year);
         
         
         
    
         if (sp == NULL) {        /* If memory can't be allocated */
               
            printf("Cannot malloc\n");
            exit(1);
         }
         free (sp);
    }
    Last edited by nizbit; 02-16-2005 at 05:17 PM.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,166
    I don't even see printpc in your code.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Oct 2004
    Posts
    76
    Changed. Older compile log.

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,166
    Well, the problem is that s.ssn is a pointer to type char and print_ssnum() expects an int.
    If you understand what you're doing, you're not learning anything.

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >print_ssnum(s.ssn)
    ssn is not defined in your structure (you have lots of dots in there though!?)
    What is it?
    The function print_ssum() requires an int as a parameter, if ssn isn't an int, then the compiler will complain.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 12:38 PM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Flood of errors when include .h
    By erik2004 in forum C++ Programming
    Replies: 14
    Last Post: 12-07-2002, 06:37 AM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM
  5. Calling a Function From A Class
    By Okiesmokie in forum C++ Programming
    Replies: 8
    Last Post: 06-28-2002, 10:09 PM

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