Thread: C Term Project( struct, read files) Please Help

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

    C Term Project( struct, read files) Please Help

    I am working on my term project and I need help. there are some parts of it I couldnt do. the question is:
    ---------------
    1. Write a program to create a stock for the products of a company. The following details should be stored in the system
    a. Name of the product
    b. Number of items available
    c. Unit price
    The program should let the user to look for a product using its name. Also it should be possible to update the number of items available. The program should store the data in a file for later use. On running the program the data from the file will be loaded into the memory
    -------------

    And I tried to solve it with examples in my course book . this is what I did so far. I am having difficulties about case 2.I messed up at case 2.If you see something wrong about my solution plaese help me.my english is not good. I hope you understand me.My solution so far:
    ----------------------------
    http://ipv4.pastebin.ca/515827I put it here. is there anyone can help me about this problem.
    Last edited by bttf; 05-28-2007 at 05:41 AM.

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    * Don't use feof() to control loops, see the FAQ
    * Use fgets() then sscanf() rather than scanf() to read input from the user (because your leaving the unused chars in the stream)

    FILE ptdatabase;
    You mean?
    Code:
    FILE * ptdatabase;
    char productname[];
    Dunno about C99, but you have to specify the size (yes you still have to ask for space on the stack)

    * A "few" more syntax errors (like Line 56-57), but I don't have the time to list them all.

    Fix your indenting, and do a pastebin it's just too hard to read (If you don't know what pastebin is, Google it)
    Last edited by zacs7; 05-28-2007 at 05:17 AM.

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

    Unhappy

    Quote Originally Posted by zacs7 View Post
    * Don't use feof() to control loops, see the FAQ
    * Use fgets() then sscanf() rather than scanf() to read input from the user (because your leaving the unused chars in the stream)



    You mean?
    Code:
    FILE * ptdatabase;

    Dunno about C99, but you have to specify the size (yes you still have to ask for space on the stack)

    * A "few" more syntax errors (like Line 56-57), but I don't have the time to list them all.

    Fix your indenting, and do a pastebin it's just too hard to read (If you don't know what pastebin is, Google it)
    thanks. you r right about FILE *ptdatabase. Are there any major problem with my solution.?

  4. #4
    Registered User
    Join Date
    May 2007
    Location
    Australia, Melbourne.
    Posts
    5
    bttf

    Your logic in solving the problem is correct. There are a few syntax errors which i assume were mistakes in typing i.e forgetting to terminate a structure defination among others.

    Code:
                                      case '3':
                                                    printf("\nthnaks for using the program");
                                                    return 0; <======[ could be avoided]
    
                                                    break;
                                      
                                      default:
    The logical error which i could point out is the CASE 3: which uses return to terminate the program. However there would be a better way to terminate the program since your do..while() loop has a condition just use it to get out of the program. The point is using all the code written if ur intent was to terminate the way you are terminating you might as use a do..while(1)
    Hope it helps.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assignment HELP!!
    By cprogrammer22 in forum C Programming
    Replies: 35
    Last Post: 01-24-2009, 02:24 PM
  2. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 09:05 AM
  3. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 03:25 AM
  4. Search Engine - Binary Search Tree
    By Gecko2099 in forum C Programming
    Replies: 9
    Last Post: 04-17-2005, 02:56 PM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM