I Need Help

This is a discussion on I Need Help within the C Programming forums, part of the General Programming Boards category; hey Im useing Microsoft Visual C++ 6.0 to program a C program (i think this is the problem ) but ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    2

    I Need Help

    hey
    Im useing Microsoft Visual C++ 6.0 to program a C program (i think this is the problem ) but anyway i dont have a choice. The problem is very simple but I cant figure it out.
    I have three files
    header
    main
    and the one that my functions are defined in and when I compile I get a error saying
    lab2.obj : error LNK2001: unresolved external symbol "int __cdecl SetSwitchParm(void)" (?SetSwitchParm@@YAHXZ)
    Debug/lab2.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.
    Code:
    This is the .h
    #define MAX 32
    
    void SetSwitchParm(void);
    
    struct Switch {
    	
    	int iProbStateChange[1];
    	int iProbGlich[1];
    	int iDebouncer[1];
    	int iPresSateSwitch[1];
    
    }SwitchData[MAX];
    
    THe .c - file where the functions are defined
    #include <stdio.h>
    #include <stdlib.h>
    #include "Switch.h"
    
    void SetSwitchParm(void)
    {
    	int lol;
    	lol= 8;
    	printf("\n\n\n\nit works\n");
    	return 0;
    }
    
    int GetSwitchParm(int iSwitchID, int iParm)
    {
    	return 0;
    }
    and the main 
    #include <stdio.h>
    #include "Switch.h"
    #include <stdlib.h>
    
    int main()
    {
    	int iNumSwitches;
    	int h;
    
    	SetSwitchParm();//this is the part that wont work 
    	{
    		printf("Please enter the number of switches: ");
    		scanf("%d", &iNumSwitches);
    
    	
    		if(iNumSwitches > 32){
    			printf("Please try again the program accepts switches from 1 to 32,\n");
    			printf("you have entered %d. Please try again.\n\n", iNumSwitches);
    		
    		}
    		if(iNumSwitches <= 32)
    			break;
    	}
    	printf("\nhi\n");
    	return 0;
    }
    Thanks Guys
    HOD
    Last edited by Salem; 09-22-2004 at 12:02 PM. Reason: code tags added - read the READ BEFORE POSTING

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    You need to make sure BOTH your .c files are in the project
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    2

    Thanks

    In the instructions i got it said one file has to be .cpp and the other .c and the last one .h turns out the .c is wronge it has to be .cpp instead.
    later

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by HODARKNESS
    In the instructions i got it said one file has to be .cpp and the other .c and the last one .h turns out the .c is wronge it has to be .cpp instead.
    later
    It turns out, this is wrong if you want to compile as C. The ".cpp" extension means, naturally, to comple as C++. There is a difference.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

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