January 26th, 2013, 01:18 PM
Help with Structures
Currently I am working with structures, however I am not quite sure how to use the printf function after the input has been stored. Below is my code. Suggestions? Thanks in advance by the way
printf("HELP HERE PLEASE");
January 26th, 2013, 01:21 PM
students[a] = read();
January 26th, 2013, 02:03 PM
You've created a new datatype called stud. You then declared an array, all, whose elements are of type stud.
makes no sense whatsoever. There is no array named "stud". There is, however, an array named "all", so you should be using it instead.
The syntax for accessing a field in a struct is this: <struct variable>.<fieldname>
So to access the aver field of the second struct in the array, you would write this: all.aver
January 26th, 2013, 08:56 PM
Thanks for the help. I have on final question. I dont want to type in all the data when it comes to doing a test run of my program. Is it possible to read all of the input from a text file?
January 27th, 2013, 12:37 AM
Of course you can read input from a file.
can be written as
From there, it's just a small step to
FILE *fp = fopen("data.txt","r");
January 27th, 2013, 02:58 AM
If your manual input is via stdin (i.e. you are using standardio functions such as getchar() etc.), then you can use redirection to take input from a file rather than manual input. So for example if you have a file grades.dat containing:
Originally Posted by bass123
And a program called grades.exe, you can redirect the file to stdin thus:
and the data will be input as if you had typed it from the keyboard.
This approach means that you can write the code for manual input but test with a file rather than specifically writing it for file access as suggested by Salem. The choice would depend on your requirements.
January 28th, 2013, 04:33 AM
This is meaningful way: