Thread: Need assistance to get started

  1. #1
    Lost Code ;)
    Join Date
    Jun 2004
    Posts
    1

    Need assistance to get started

    I have been racking my brain on trying to finish this homework.
    I am getting an error right where I start my FOR loop. (subscript requires array or pointer type)

    I don't know what I am doing wrong, I modified a working code and added my code to it, but I can't compile it. Anyone please help!!

    thanks!

    Code:
    { 
       struct felix 
       { 
       int empno; 
       float wages; 
       }; 
       felix record; 
       int i; 
       FILE *main_file; 
       main_file = fopen("master_f", "wb"); 
       fprintf(stdout, "Enter employee numbers and wages: \n"); 
       fprintf(stdout, "When done, enter a zero twice \n"); 
       fscanf(stdin, " %s %f", &record.empno, &record.wages);//Stdin is the file pointer 
       for(i = 0; record.empno[0] != '0'; ++i) 
       { 
          fprintf(main_file, " %s %f \n", record.empno, record.wages);//Write to the file 
          fscanf(stdin, " %s %f", &record.empno, &record.wages); 
       } 
       fclose(main_file);//This should be last pertaining to file open and close. 
       fprintf(stdout, "There were %d records entered\n", i); 
    }

  2. #2
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    You declared empno as an int, is that what you wanted? If so, why do you use %s and [0]? Either change empno to be a string, or change your code to treat it like an int.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >FILE *main_file;
    Why not fstreams?

    >fprintf(stdout, <snip>
    You could just use printf, it prints to stdout without your having to specify it.

    >fscanf(stdin, <snip>
    Ditto. scanf is equivalent to fscanf(stdin, ..., ...).

    >fclose(main_file);
    This wouldn't be needed if you used fstreams.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help getting started..matrices
    By BobDole11 in forum C Programming
    Replies: 7
    Last Post: 11-15-2008, 09:51 PM
  2. Help getting started :(
    By blackocellaris in forum C Programming
    Replies: 4
    Last Post: 11-05-2006, 06:50 PM
  3. Getting started
    By panzeriti in forum Game Programming
    Replies: 3
    Last Post: 06-28-2003, 10:13 AM
  4. Getting Started
    By UnclePunker in forum Game Programming
    Replies: 3
    Last Post: 04-11-2003, 12:34 PM
  5. How to get started?
    By anoopks in forum Linux Programming
    Replies: 0
    Last Post: 01-14-2003, 03:48 AM