need help with debugging

This is a discussion on need help with debugging within the C Programming forums, part of the General Programming Boards category; Im a big programming newbie and need to get my program running for my class programing project. Code: #include <stdio.h> ...

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    2

    need help with debugging

    Im a big programming newbie and need to get my program running for my class programing project.
    Code:
    #include <stdio.h>
    
    
    //function declarations
    int getreport     (FILE* spIN, 
    				int* partnum, int* price, 
    				int* qty, int* reorder, int* minorder);
    
    int writereport   (FILE* spOUT, int  partnum, int price, int qty,
    				   int reorder, int minorder, int*  orderamt);
    
    void calcorderamount (int reorder, int minorder);
    				
    
    
    
    int main(void)
    {
    //local declarations
    FILE* spIN;
    FILE* spOUT;
    
    int partnum;
    int price;
    int qty;
    int reorder;
    int minorder;
    int* orderamt;
    
    //statements
    
    printf("begin inventory report\n\n");
    
    spIN = fopen ("C:\\stuff.TXT", "r");
    	if (!(spIN = fopen ("C:\\stuff.TXT", "r")))
    	{
    	printf("error opening stuff.txt\n");
    	return 101;
    	}//input file error check
    
    	if (!(spOUT = fopen ("C:\\inventoryreport.TXT", "w")))
    		{
    		printf("error creating inventory file\n");
    		return 102;
    		}//output file error check
    
    	while (getreport
    		  (spIN, &partnum, &price, &qty, &reorder, &minorder))
    		{
    		calcorderamount (reorder, minorder);
    		writereport   (spOUT, partnum, price, qty, reorder, minorder, orderamt);
    		}//while
    
    	fclose (spIN);
    	fclose (spOUT);
    
    	printf ("end of inventory report\n");
    	return 0;
    }
    
    
    int getreport     (FILE* spIN, int* partnum, int* price, 
    				int* qty, int* reorder)
    {
    //local declarations
    	int ioresult;
    	int minorder;
    	
    
    //statements
    	ioresult = fscanf(spIN, "%d%f%d%d%d", partnum, 
    					 price, qty, reorder, minorder);
    	if (ioresult == EOF)
    		return 0;
    	else if (ioresult !=5)
    		{
    		 printf("\aError reading data\n");
    		 return 0;
    		}//error check
    	else
    		return 1;
    }
    
    void calcorderamount (int reorder, int minorder)
    {
    //statements
    int* orderamt;
    int* qty;
    
    	*orderamt = (reorder + minorder);
    	if	(*qty < *reorder)
    		*qty = *orderamt;
    	else
    		*qty = *qty;
    	return;
    } //clacgrade
    
    
    int writereport   (FILE* spOUT, int  partnum, int price, int qty, 
    				   int reorder, int minorder, int  orderamt)
    {
    //statements
    	fprintf(spOUT, "%d %f %d %d %d %d", partnum, 
    					 price, qty, reorder, minorder, orderamt);
    	return 0;
    }//writereport
    it's sloppy i know. but i can't figure out that "illegal indirection" error at my if else statement.

    i am using visual c++ 2005 express edition as a compiler (and my professor said ONLY to use this compiler).

    Help will be MUCH appreciated.

    edit: here is what i am trying to accomplish: when the quantity on hand (qty) falls below the reorder point (reorder), it adds the minimum order (minorder) to the reorder point to produce the order amount (orderamt). otherwise, the quantity on hand is left alone and reprinted in the order amount.
    Last edited by Wiggles; 07-20-2010 at 08:33 PM. Reason: incomplete info

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It helps if you actually tell us where you're getting the error. But:
    Code:
    void calcorderamount (int reorder, int minorder)
    {
    //statements
    int* orderamt;
    int* qty;
    
    	*orderamt = (reorder + minorder);
    	if	(*qty < *reorder)
    		*qty = *orderamt;
    	else
    		*qty = *qty;
    	return;
    } //clacgrade
    Neither of those pointers actually point anywhere. reorder isn't a pointer. Also, what is your else supposed to be doing?


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

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    2
    opps. i left out some info. read the bottom of the first post

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,663
    The same problem is still there.
    orderamt and qty point to nowhere.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    @Wiggles, If you enable your compiler warnings to maximum and pay attention to them, half of your bugs might have been spotted. You may want to use lint also.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help on debugging
    By Masterx in forum C++ Programming
    Replies: 56
    Last Post: 01-30-2009, 09:09 AM
  2. Dev-C++: Problems with Breakpoint Debugging
    By Thileepan_Bala in forum C Programming
    Replies: 1
    Last Post: 01-17-2008, 09:48 AM
  3. Problem in debugging in Eclipse
    By Bargi in forum Linux Programming
    Replies: 1
    Last Post: 08-21-2007, 09:53 AM
  4. gdb no debugging symbols found
    By Laserve in forum Linux Programming
    Replies: 8
    Last Post: 09-17-2006, 08:56 AM
  5. Debugging book recommendation
    By dagans in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 09-13-2005, 07:35 PM

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