Jump to content

how can i debug this?

- - - - -

  • Please log in to reply
10 replies to this topic

#1
atoivan

atoivan

    Learning Programmer

  • Members
  • PipPipPip
  • 61 posts
any time i run the codes i get these error messages.

/tmp/ccffCVmG.o: In function `main':

work.c:(.text+0x1e1): undefined reference to `create_new_stock'

work.c:(.text+0x1e8): undefined reference to `display_stock'

work.c:(.text+0x1ef): undefined reference to `sales'

work.c:(.text+0x1f6): undefined reference to `modify'

collect2: ld returned 1 exit status

i do not know how to debug this. help me debug this.

this is my codes

#include <stdio.h>

#include <stdlib.h>

#include <ctype.h>

#include <string.h>


void create_new_stock(void);

void display_stock(void);

void sales(void);

void modify(void);

void Additem(void);

void Viewitems(void);

void Viewcategory(void); 

void Editcategory(void);

void Edititems(void);

void Edit(void);

void Deleteitem(void);

void Deletecategory(void);

void PrintBeeper(void);

void CreateFile(void);

void DeleteFile(void);




double 	u_prx = 0.0; 			// unit price per item

double 	total=0.0; 				// total sold per item

double 	G_total=0.0; 			// grand total per day

double 	amut_b=0.0; 			// buying price (bulk)

double 	amut_u=0.0;				//	buying price per item(unit)

double 	S_prx_Blk=0.0;			//	selling price in bulk

double 	S_prx_u=0.0;			//	selling price in unit

double 	T_amut_blk=0.0;			//  total amount in cash (bluk)

double	T_amut_u =0.0;			//	total amount in cash (unit)

double  qty_sold = 0.0;			// quantity sold per item

int 	T_qty_bulk =0;			//  quantity of items in bulk

int 	T_qty_u =0;				//  quantity of items in unit

int     G_T_qty_bulk=0;			//grand total in bluk

int		G_T_qty_u=0;			//grand total in unit

int	   	qty_u= 0; 				// quntity in bottle per item

int    	qty_left = 0; 			// quntity left per item

int    	qty_bulk = 0;			// quantity in warehouse 


char cate[20];					// categories of items

char iname[20]; 				// item name

char code[6]; 					// item code


int main()

{

char sele; // seletion of data

system("cls");

puts(" Welcome to my sales Program");

puts("<1> \t Create a new stock ");

puts("<2> \t Display Stock");

puts("<3> \t Sales");

puts("<4> \t Modify");

puts("<5> \t exit");


puts("Enter selection");

scanf("%c",&sele);


					

switch (sele)

{

case '1':

create_new_stock();

break;

case '2':

display_stock();

break;

case '3':

sales();

break;

case '4':

modify();

break;

case '5':

exit(1);

break;


	}


void create_new_stock()

{

	int bra=0;

printf("Enter Category ");

scanf("%s",cate);

printf("How many brands do u want to add?");

scanf("%d",&bra);

for(;;)

{

printf("Enter brand name");

scanf("%s",iname);

printf("Enter Buying price(bulk)");

scanf("%lf",&amut_b);

puts("Enter Quantity in bulk");

scanf("%d",&qty_bulk);

puts("Enter Quantity of items (number of items in a box)");

scanf("%d",&qty_u);

T_qty_u=qty_bulk*qty_u;

T_amut_blk=amut_b/qty_u;

puts("Enter Selling price for(box)");

scanf("%lf",&S_prx_Blk);

puts("Enter selling price for unit");

scanf("%lf",&S_prx_u);


}

}

	


void display_stock()

{


	

}


void sales()

{


	

	}


void modify()

{


	


}

}

is there something i am missing here

#2
fread

fread

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 787 posts
At a glance you have functions nested inside your main function. That is not allowed. Remove all of the functions you have nested inside of your main.
Perfection of means and confusion of ends seem to characterize our age. Albert Einstein :confused:

#3
atoivan

atoivan

    Learning Programmer

  • Members
  • PipPipPip
  • 61 posts

fread said:

At a glance you have functions nested inside your main function. That is not allowed. Remove all of the functions you have nested inside of your main.

then how do i go about it then pls teach me

#4
notes

notes

    Learning Programmer

  • Members
  • PipPipPip
  • 48 posts
Just put all your functions(not only declarations) before, or after
int main()

{

    ...

}

Im not much of C programmer - more c++ - but it seems you have much work ahead of you.
Also try using some tabulations to organize code. Also programmers that work on other OS can have problems with " system("cls"); "
function.

GL ;-)
Remebre about KISS & DRY

#5
atoivan

atoivan

    Learning Programmer

  • Members
  • PipPipPip
  • 61 posts

notes said:

Just put all your functions(not only declarations) before, or after
int main()

{

    ...

}

Im not much of C programmer - more c++ - but it seems you have much work ahead of you.
Also try using some tabulations to organize code. Also programmers that work on other OS can have problems with " system("cls"); "
function.

GL ;-)

after your advice i changed the codes


how can i make the selection work

#include <stdio.h>

#include <stdlib.h>

#include <ctype.h>

#include <string.h>


void create_new_stock(void);

void display_stock(void);

void sales(void);

void modify(void);

void Additem(void);

void Viewitems(void);

void Viewcategory(void); 

void Editcategory(void);

void Edititems(void);

void Edit(void);

void Deleteitem(void);

void Deletecategory(void);

void PrintBeeper(void);

void CreateFile(void);

void DeleteFile(void);

void sel();




double 	u_prx = 0.0; 			// unit price per item

double 	total=0.0; 				// total sold per item

double 	G_total=0.0; 			// grand total per day

double 	amut_b=0.0; 			// buying price (bulk)

double 	amut_u=0.0;				//	buying price per item(unit)

double 	S_prx_Blk=0.0;			//	selling price in bulk

double 	S_prx_u=0.0;			//	selling price in unit

double 	T_amut_blk=0.0;			//  total amount in cash (bluk)

double	T_amut_u =0.0;			//	total amount in cash (unit)

double  qty_sold = 0.0;			// quantity sold per item

int 	T_qty_bulk =0;			//  quantity of items in bulk

int 	T_qty_u =0;				//  quantity of items in unit

int     G_T_qty_bulk=0;			//grand total in bluk

int		G_T_qty_u=0;			//grand total in unit

int	   	qty_u= 0; 				// quntity in bottle per item

int    	qty_left = 0; 			// quntity left per item

int    	qty_bulk = 0;			// quantity in warehouse 


char cate[20];					// categories of items

char iname[20]; 				// item name

char code[6]; 					// item code


void sel()

switch (sele)

{

case '1':

create_new_stock();

break;

case '2':

display_stock();

break;

case '3':

sales();

break;

case '4':

modify();

break;

case '5':

exit(1);

break;


	}

int main()

{

char sele; // seletion of data


puts(" Welcome to my sales Program");

puts("<1> \t Create a new stock ");

puts("<2> \t Display Stock");

puts("<3> \t Sales");

puts("<4> \t Modify");

puts("<5> \t exit");


puts("Enter selection");

scanf("%c",&sele);


return 0;

		}

now i am having this errors
work.c:48: error: expected declaration specifiers before ‘switch’ 

work.c:68: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token

work.c:82: error: expected ‘{’ at end of input

i am using a geany compiler in ubuntu

#6
fread

fread

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 787 posts
Doing this:

void sel() 
switch (sele) { 
case '1': create_new_stock(); 
break; case '2': display_stock(); 
break; case '3': sales(); 
break; 
case '4': modify(); 
break; 
case '5': exit(1); break;
      }
 int main() { 
char sele; // seletion of data  puts(" Welcome to my sales Program"); 
puts("<1> \t Create a new stock "); 
puts("<2> \t Display Stock"); 
puts("<3> \t Sales"); 
puts("<4> \t Modify"); 
puts("<5> \t exit");  
puts("Enter selection"); 
scanf("%c",&sele);  
return 0;        
 }
says there is much confusion. As a first Lesson in programming you should understand parenthesis. You seem to also be confused with the use of functions. Your code is a bit difficult to read since there is no indentation; larger programs could be difficult to read. All of your variables are declared as global(i'm wondering if this is on purpose or this is by chance). And if you are putting functions in main and not sure how to call them then you are probably moving to fast. I suggest you take a more modular approach, understand what caused and error then attempt to fix. There is a lot you still need to learn for instance '1' is not the same as numeric 1. Get a descent book on C or C++ programming, it will definitely do you some good.
Perfection of means and confusion of ends seem to characterize our age. Albert Einstein :confused:

#7
notes

notes

    Learning Programmer

  • Members
  • PipPipPip
  • 48 posts
First of all, you are now missing brackets you have :
void sel()

switch (sele)

it should be:
void sel() {

switch (sele)

Don't forget about ending bracket in the end of the function.

Now let's talk about :
switch (sele)
Every variable used should be first declared.
Also everything you declare stays within { } brackets, but you can pass it to another function,
you do this when you call for a function.
So, If your function void sel() wants to use variable that was declared and had assigned some value in another function,
You have to pass it void sel(char); then call
void sel(char sele) { ... }
This a few information about nesting and I strongly recommend you to re-read your book from the beginning and don't skip any chapters.
Remebre about KISS & DRY

#8
fread

fread

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 787 posts
void sel(char selectedVal){
  switch(selectedVal)
   {
    /* cases goes here */
   }
}

Perfection of means and confusion of ends seem to characterize our age. Albert Einstein :confused:

#9
atoivan

atoivan

    Learning Programmer

  • Members
  • PipPipPip
  • 61 posts
thank you guys for the help thank u

#10
fread

fread

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 787 posts
Anytime. oh and don't forget to get a book!
Perfection of means and confusion of ends seem to characterize our age. Albert Einstein :confused:

#11
atoivan

atoivan

    Learning Programmer

  • Members
  • PipPipPip
  • 61 posts

fread said:

Anytime. oh and don't forget to get a book!
ok i will




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users