Thread: function problems

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    2

    Thumbs up function problems

    ok so i am trying to call a function with two structures as arguments. when i try and compile it with gcc i get these errors

    gcc -Wall -pedantic -c server.c
    server.c:34:45: warning: C++ style comments are not allowed in ISO C90
    server.c:34:45: warning: (this will be reported only once per input file)
    server.c: In function ‘main’:
    server.c:141: error: expected expression before ‘struct’
    server.c:141: error: too few arguments to function ‘compute’
    server.c:155: error: expected expression before ‘struct’
    server.c:155: error: too few arguments to function ‘compute’
    server.c:201: error: expected ‘while’ at end of input
    server.c:201: error: expected declaration or statement at end of input
    make: *** [server.o] Error 1

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <malloc.h>
    #include <string.h>
    #include <unistd.h>
    #include <stdarg.h>
    #include <math.h>
    #include <time.h>
    #include "structure.h"
    
    int compute(struct cathedral *, struct forces *);
    
    struct cathedral *A;
    struct forces *F;
    
    int main(int argc, char **argv) {
    
    	A=(struct cathedral *) malloc (sizeof(struct cathedral));
    
    	F=(struct forces *) malloc (sizeof(struct forces));
    
    141        junk = compute(struct *A , struct *F);
    
    155       collapse=compute(struct *A, struct *F); 
    
    196		} while (collapse);
    197		
    198	} while (connection);
    199	
    200	return 0;
    201}
    I have tried a few different ways of calling the functions but haven't figured out why it doesnt work. Any ideas I could try?

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    #1
    Code:
    A=(struct cathedral *) malloc (sizeof(struct cathedral));
    
    F=(struct forces *) malloc (sizeof(struct forces));
    You shouldn't cast malloc in C.

    #2
    Code:
    junk = compute(struct *A , struct *F);
    
    collapse=compute(struct *A, struct *F);
    All you should need to do is:
    Code:
    junk = compute(A,F);
    
    collapse=compute(A,F);
    Last edited by hk_mp5kpdw; 05-07-2007 at 08:47 AM.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    2
    Awesome thanks much for the functions help. i just read up on why not to cast malloc in C thanks for the info. Any ideas on the last bit? i am not sure where the other while is needed or why. I just was missing a bracket towards the end. Thanks again for your help.
    Last edited by dahvid; 05-07-2007 at 09:07 AM. Reason: trial and error solved it

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  2. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. Problems with str.replace function
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 11-07-2001, 03:35 AM