Thread: business project

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    4

    business project

    Junior Member

    Registered: Nov 2001
    Location:
    Posts: 1
    business program

    i have just started a new business. I am creating a program but as C isn't my specialist subject I need some help for this.
    This website has come highly recommeneded and I hope you can help me. For the program I want to read from a text
    file called which I've called id.txt this contains characters and numbers
    The program will then read the numbers and generate a sorted dynamic linked list. I want this to be done from the
    (largest to smallest), where each node of the linked list would contain a single integer. The program should then
    traverse the linked list the resultant linked list on screen.

    I have already stared by readying in the file but am stuck with the link list. What i've done is shown below.

    #include<stdio.h>
    #include<stdlib.h>
    FILE *INFO-FILE; /*FILE POINTER*/

    open(char *Myfile)

    {
    if ( (INFO-FILE = fopen( Myfile,"r")) == NULL)
    {
    printf("Can't open %s\n",Myfile);
    exit(1);
    }

    }
    main(){
    int choice;
    char c;

    printf("\nThis program is designed by David\n");
    printf("1 - Reads the text file\n");
    printf("2 - creates a linklist between text file\n");
    printf("3 - print output\n");
    printf("4 - Any other number enter return void\n");
    printf("please enter your choice");
    scanf("%d",&choice);


    switch(choice){
    case 1:

    open("id.txt");
    printf("\n");


    printf("\n");

    break;



    case 2:
    break;

    case 3:
    break;

    default:
    printf("ERROR***** ERROR******ABORT******\n");

    }
    return; /*FINISH*/
    }

  2. #2
    Unregistered
    Guest
    define a structure like

    struct node
    {
    int number;
    char data[100]; /* assuming data can be upto
    100 characters */
    struct node* before;
    struct node* after ;
    };

    /* "after" points to next node
    "before" points to previous node

    for 1st node "before" is "null"
    for last node "after" is "null"

    */

    read 1st item from the file
    create 1st node

    ( store the pointer of 1st node in a variable say "ptr_1st"

    ptr_1st should be of datatype struct node*

    )

    then read next item from file and create the second node

    now store the pointer of the second node
    in the "after" member of 1st node

    like wise continues until all items in the file are read

    "after" member of last node should be "null"



    now you will have a linked list but
    nodes not are not sorted .

    you can travese through the linked list
    ( by using the pointer "ptr_1st"
    which points to the 1st node in list
    and "after" member of ist node points to 2nd
    node and so on until "after" is "null"
    )
    and sort it as per your need .


    avinna

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 09:05 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. Dynamic Binding
    By gpr1me in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2006, 09:01 AM
  4. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM