Thread: First C program ? ? error: syntax error before "int"

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    9

    First C program ? ? error: syntax error before "int"

    Here is the error message:

    assignment1.c: In function `gateInput':
    assignment1.c:24: error: syntax error before "int"

    and here is the code:

    #include "stdlib.h"
    #include "assert.h"
    #include "stdio.h"
    #include "circuit.h"

    int main(int argc, char * argv[])
    {
    int i;
    struct gate * g;
    printf("type an integer:\n");
    scanf("%d", &i);
    g = gateInput(&i);
    gatePrint(g);

    return 0;

    }

    struct gate * gateInput(int * value)
    {
    struct gate * d = gateConstant(int * value);
    return d;
    }

    struct gate * gateConstant (int value)
    {
    struct gate * r = (struct gate *) malloc(sizeof(struct gate));
    assert(r != 0);

    if (value == 0)
    return gateZero();
    if (value == 1)
    return gateOne();
    }

    struct gate * gateZero()
    {
    struct gate * r = (struct gate *) malloc(sizeof(struct gate));
    assert(r != 0);
    r -> gateType = ConstantZeroGate;
    printf("EnteredValue: ", &r);
    return r;
    }

    struct gate * gateOne()
    {
    struct gate * r = (struct gate *) malloc(sizeof(struct gate));
    assert(r != 0);
    r -> gateType = ConstantOneGate;
    printf("EnteredValue: ", &r);
    return r;
    }

    void gatePrint (struct gate * e)
    {
    struct gate * print = e;
    printf("The entered Value: ", &print);
    }
    Last edited by Jasonx521; 10-02-2006 at 05:35 PM.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >struct gate * d = gateConstant(int * value);
    You're calling a function, not declaring one:
    Code:
    struct gate * d = gateConstant(value);
    And please use code tags, preferrably with well formatted code.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    9
    thank you.. obviously

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >struct gate * d = gateConstant(int * value);
    I think you want:
    Code:
    struct gate * d = gateConstant(*value);
    You want to pass gateConstant an int, not a pointer to int.

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >struct gate * d = gateConstant(*value);
    Ah, yes. Benefits of looking at the "formatted" code rather than the code with lots of random newlines all over the place before the OP edited it.
    My best code is written with the delete key.

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    903
    Oh, and you might want to declare 'gate' like this so that you can stop writing 'struct' everywhere:
    Code:
    typedef struct
    {
    } gate;
    
    gate* gate_ptr;

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Quote Originally Posted by Prelude
    >struct gate * d = gateConstant(*value);
    Ah, yes. Benefits of looking at the "formatted" code rather than the code with lots of random newlines all over the place before the OP edited it.
    I guess I should be glad I didn't see it before editing.

  8. #8
    Registered User
    Join Date
    Oct 2006
    Posts
    9
    Okay I made some progress, but now is where I 'm really stuck... how would I set up gateAnd, GateOr etc..?

    I know the logical math and how to add binary, but never tried to replicate it with a program?

    I will need to replicate a circuit also using a half adder, and fulladder? I have looked over wikipedia, but still a little confusing. ?
    Last edited by Jasonx521; 10-02-2006 at 09:59 PM.

  9. #9
    Registered User
    Join Date
    Oct 2006
    Posts
    9
    Here is the code:

    Code:
    #include "stdlib.h"
    #include "assert.h"
    #include "stdio.h"
    #include "circuit.h"
    
    int main(int argc, char * argv[])
    {		
    	struct gate * g = gateInput("Type an Integer");
    	gatePrint(g);		
    	return 0;
    }
    
    	struct gate * gateInput(char * prompt) 
    	{		
    		int i;
    		printf(prompt);
    		scanf("%d", &i);
    		return gateConstant(i);
    	}
    
    	struct gate * gateConstant (int value)
    	{
    		struct gate * r = (struct gate *) malloc(sizeof(struct gate));
    		assert(r != 0);
    
    		if (value == 0)
    		return gateZero();
    
    		if (value == 1)
    		return gateOne();
    	}
    
    	struct gate * gateZero()
    	{
    		struct gate * r = (struct gate *) malloc(sizeof(struct gate));
    		assert(r != 0);
    		r -> gateType = ConstantZeroGate;
    		return r;
    	}
    
    	struct gate * gateOne()
    	{
    		struct gate * r = (struct gate *) malloc(sizeof(struct gate));
    		assert(r != 0);
    		r -> gateType = ConstantOneGate;
    		return r;
    	}
    
    	void gatePrint (struct gate * e)
    	{
    		printf("The entered Value: %d \n",*e);
    	}
    
    	int gateEval (struct gate * e)
    	{
    		
    	}
    
    	void intToBit (int value, int * eights, int * fours, int * twos, int * ones)
    	{
    		assert ((value >= 0) && (value < 16));
    		*ones = value % 2;		
    	}
    
    	struct gate * gateNot(struct gate * arg)
    	{
    	
    
    	}
    	
    	struct gate * gateAnd(struct gate * left, struct gate * right)
    	{
    
    	}
    
    	struct gate * gateOr(struct gate * left, struct gate * right)
    	{
    
    	}
    
    	struct gate * gateXor(struct gate * left, struct gate right)
    	{
    
    	}
    
    	void halfAdder(struct gate * left, struct gate * right, struct * carryin, struct gate **sum)
    	{
    
    	}
    Last edited by Dave_Sinkula; 10-02-2006 at 09:42 PM. Reason: Added [code][/code] tags -- learn to use them yourself. [Sorry, Sly.]

  10. #10
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    See my signature? Edit your post and wrap your code in that tag.
    Sent from my iPadŽ

  11. #11
    Registered User
    Join Date
    Oct 2006
    Posts
    9
    Quote Originally Posted by SlyMaelstrom
    See my signature? Edit your post and wrap your code in that tag.
    Thank you..

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, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM