Thread: File input question

  1. #16
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    or course remember this warning in the man page
    Code:
    BUGS
           Never use this function.  This function modifies its first
           argument.   The  identity  of  the delimiting character is
           lost.  This function cannot be used on constant strings.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  2. #17
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Code:
    float take_score (char first_names[][MAX_LETTERS], 
    				  char middle_names[][MAX_LETTERS], 
    				  char last_names[][MAX_LETTERS], 
    				  int student_num);
    why not use a structure instead of passing the arrays as arguments?

    Code:
    	char grades[MAX_STUDENTS];
    	char first_names    [MAX_STUDENTS][MAX_LETTERS];
    	char middle_names   [MAX_STUDENTS][MAX_LETTERS];
    	char last_names     [MAX_STUDENTS][MAX_LETTERS];
    	float student_grades[MAX_STUDENTS][3];
    	float GPAs[MAX_STUDENTS];
    	float final_scores[MAX_STUDENTS];
    because this is what happens. You've got this completely unweildy grouping of data that really deserves to be put in a structure.

    Code:
    struct name {
     char first[MAX_LETTERS];
     char middle[MAX_LETTERS];
     char last[MAX_LETTERS];
    };
    struct student {
     struct name name;
     float grade;
     char letter_grade;
    //...etc.
    };
    
    // then:
    
    struct student[MAX_STUDENTS];
    parsing text can be achieved in many different ways - the most robust implementations typically set up a finite state machine of some sort, simpler ones utilize strtok, strstr, and functions like these:
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  4. Beginner Text File Input Question
    By Ruggles in forum C++ Programming
    Replies: 2
    Last Post: 11-12-2006, 02:18 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM