Checking for the end of a line

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TimNick90
    New Member
    • Dec 2007
    • 8

    Checking for the end of a line

    I am writing a program for a class of mine to pull a students initials as well as a list of their letter grades from a file and calculate their gpa. In the file there is one student and their grades per line. Each student can have an infinate amount of grades, and their could be an infinate amount of students. I am having trouble with starting a new students gpa. The only way I can think of would be to check for the end of a line. The only problem with this is I am using a string to take the initials and grades from the file and using a char to check for '\n' would be off set, due to the string reaching the end of the line before the char. If anyone could help me figure out a way to solve this it would be much appreciated.

    Thanks,
    TimNick

    PS: if you wish to see my code I can PM it to you.
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    Originally posted by TimNick90
    ...The only problem with this is I am using a string to take the initials and grades from the file and using a char to check for '\n' would be off set, due to the string reaching the end of the line before the char...
    Could you elaborate on this point? What exactly are you trying to do, and why exactly do you think it won't work?

    If necessary, you can post a portion of your code to the thread - just make sure you use [CODE] tags.

    Comment

    • TimNick90
      New Member
      • Dec 2007
      • 8

      #3
      Originally posted by Ganon11
      Could you elaborate on this point? What exactly are you trying to do, and why exactly do you think it won't work?

      If necessary, you can post a portion of your code to the thread - just make sure you use ['CODE'] tags.
      The program pulls the informations out of a file and then prints the sutdents initials as well as their gpa based on their grades given. The format for the informations in the file is:

      Code:
      JKL A B C D E
      MNO A B B
      So it should look like this:

      Code:
      Sutdent Initials       Students GPA
           JKL                             2
         MNO                       2.333
      What I have it doing is running through a loop checking for the end of the file so it will get all of the information. It also needs to be running through another loop checking for the end of the line. The only way I know of to check for the end of a line is with a char and check to see if it equals '\n'. I am unsure of how to do this because I am using a string to pull the initials and grades. Won't the string get to the end of the line before the char if it's running throught the same loop? This would cause the string to start taking information from the next line while the char is still on the first one.

      Comment

      Working...