Thread: help with code

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    34

    Question help with code

    beginner needs help with code

    to read from data file to 2 dim array
    display data to screen
    open output file
    display data to screen in reverse order
    write data to output file in reverse order

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    We're not going to do your homework for you -- at least not from scratch. Attempt it and if it's still not working then post what you get (and use code tags). We'll help you fix your errors from there.

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    34
    i'll show you what i have

    #include <stdio.h>
    #include <stdlib.h>

    FILE * Fileptr;

    struct Client //* defines the 2 dim array*//
    {
    char Lname[15]
    char fname [15]
    int count;
    }Record[];


    main()
    {

    int count;
    for (count=0;count<5;count++)
    }
    client[count]=fill (client[count]); //* fill the array *//

    }

    while (fscanf(Fileptr, "%C, &Lname) != EOF));
    {
    fscanf(FilePtr, "%c, &Fname);
    {

    int count;
    for (count=0;count<5;count++)
    {
    fread(&Client[count], sizeof(Record,, 1, FilePtr);//*read into*//
    }
    fclose(FilePtr);
    return(0);
    }

    printf("First Name: "%c" Last Name: "%c , Fname, Lname);

    }

    fclose(FilePointer);
    {
    FilePtr = fopen ("output.dat","w");//*open output file*//
    int count =0;
    for (count=0; count <5; count++)
    {
    fwrite(&Record[count], sizeof(Client), 1, FilePtr);//*write *//
    }
    fclose(FilePtr);
    {
    FilePtr=fopen(output.dat", "r");
    int count=4;
    for(count=4;count=0;count--);
    fread(&Record[count], sizeof(client, 1, FilePtr);
    printf ("First name:" %c "Last Name" %c, Fname, Lname);
    Last edited by ddavidson; 02-12-2003 at 07:22 AM.

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>(and use code tags)
    Read this, and edit your post accordingly please.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    34

    Question

    the attached file needs some work

    I am sure that there are some very good people out there who can fix this in minutes

    Can someone show me the way


    Much Thanks

  6. #6
    Registered User Sargnagel's Avatar
    Join Date
    Aug 2002
    Posts
    166
    Code:
    if ((FilePtr = fopen("client.dat","r")) = NULL);
    it must be:
    if ((FilePtr = fopen("client.dat","r")) == NULL);
    
    for (count =4 ;count=0; count--)     
    
    I guess you want:
    for (count =4 ;count>0; count--)     // or >= 0
    Your code is very unstructured. IMHO it is very hard to read/understand.
    Do not include the function source code in main().
    And the brackets are unbalanced ... but it is hard to tell where to remove/add brackets.
    But you clearly forgot to put the function body of "int Open_File()" in brackets.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM