 Now, with this I go over to the document. Incidentally, I am going to ask a query. So, I hope you have your clicker devices. Please keep them with you, but do not switch them off right now. I will be asking this question immediately after describing the episode that I mentioned. So, in about 10 minutes time just keep your clickers ready and the request is for the workshop coordinators to ensure that their receiver machine or receiver hardware is connected and the receiver machine is switched off. This is just to request you to keep things in readiness. I will raise the quiz after about 10 minutes time. So, let me now go over. I describe to you the use of AUG. Strictly speaking it is not AUG that we are talking about. We are talking about the ability to process the data and ability to get the processed result as per our requirements. In particular we saw how to calculate batch totals, batch averages and the averages for the entire class. The incidence that I am describing happened when I showed this AUG script and actually I used the data that was processed here in my course last year. So, in the class I announced the names of students scoring high marks in the mid semester examination. Actually there is one more person with 44.5 marks in this slide the name is missing. This is I would advise all teachers to consider doing this whenever you conduct an exam for a large class. It is I think useful to just mention that these were the top performers because they appreciate it and the students get an element of what I may call desire to do better. Anyway so I announced the names of students scoring high marks in the mid semester exam. I asked each one to stand up. There are 800 students. So, there was clapping in fact where students acknowledged the good performers. Please note that the question paper was out of 45 marks. So, even 42 are really good marks 44, 44 were and half were exceptional. Anyway that is not the point. The point is what happened subsequent to that class is that when I was coming out of the class one student sitting in front stopped me and said sir I have a friend who actually should be in the top honors. Currently his marks are not given like that but he has raised the issue with his teaching assistant. Remember our question papers are evaluated by teaching assistants and he said that after the review he is sure that his friend will get higher marks and he should be in the honors list. So, I just I did not know anything I said fine if that fellow gets his marks elevated to the level above 42 please ask him to send me a email and I will be glad to include him in the honors list. After that I got an email from a student this name was Nithant Vaidya saying that he has now got his answer book back and the revised total as per the teaching assistant is 43 and half clearly he should be in the honors list. But what was most interesting and very touching was in the same email he further said that before writing this mail to me he just checked his paper again and found that in the original total that TA had done he had made a totaling mistake giving him two marks more than what should have been the correct total and therefore he said his final mark should thus be actually only 41 and half and not 43 and half which I should record these episodes I think you will all agree do not happen normally our students generally come and fight for increasing marks it is very rare that somebody comes and admits that evaluation has gone wrong in totaling and the marks are less than what have been shown there I would like you to appreciate the significance of this admission please understand that he is a first-year student okay he is ruling himself out from the recognition as a top performer and in fact the final grade in the course which by the way often changes with a difference of even point five marks given 800 students he's geopolitizing that great and please understand that as far as we were concerned our TA's had submitted the modified marks to us so we had got our records correctly our rather fixed properly and in our record he was shown to have 43 and half and the answer papers were distributed there is no reason absolutely for him to come back and tell us so he did it on his own not because of any compulsion or not at all because there was a fear that he might be discovered as a teacher I felt that these admissions are very rare and coming from a first-year student working in a competitive environment this was indeed exceptional so I did the following in the next lecture I put him his name up in an extended on-us list I just said extended on-us list his name but I did not show any marks then I briefly the recited this episode and asked the students that is respective the marks that he has got I feel that he should be in the list of top honors do you agree and the whole class agreed actually then when I asked him to stand up as I had asked the other on-us people to stand up for whom for each of whom there was a clapping earlier believe me the clapping here was roaring clapping what I understood is that all of us students like all of us really respect ethical behavior I felt glad that I actually did all this because I think it encouraged the students to imbibe some of this ethical behavior personally I believe that it is such episodes which make our lives as teachers very enjoyable and meaningful more importantly I think these episodes go a long way to increase our own resolve to be scrupulously ethical in our activities remember we as human beings are very good in quickly noticing the mistakes or the wrong behavior in others but in our own case we rarely examine ourselves I think such episode tell us to do that constantly I have found such events very very sort of not just touching but very encouraging to ask me to introspect and examine myself and the last observation I would like to make about this episode is that we often look for role models in life and we search for big names my humble observation is that role models need not be searched far and wide they exist amongst us often disguised as normal people coming out only through some small events please note that even the last seven days what I have noticed look at the interaction intense interaction that is happening between the participants and the coordinators and the coordinating staff and their colleagues I know it is happening at many centers but I find the Nakpur interaction exceptional look at our friends in Srinagar in spite of all kinds of problems they even are willing to walk or cycle down to the center to attend the classes now these are the kind of events I think which tell us a lot and my conclusion is it is up to us to recognize acknowledge and emulate the word I have used is if we so dare because to appreciate is simple but to emulate to try to follow it ourselves is difficult it requires a lot of heart and a lot of guts so if we so dare we should do that I am sorry for having taken five minutes of your time this is completely a non-technical there is nothing to do with C programming but this episode happened when I was teaching programming to 800 students from the reaction of the 800 students I felt that the students appreciated this and in fact that perhaps reflected in their subsequent ethical behavior when they themselves were required to do peer evaluation of their colleagues and give marks when there was no supervision yet they worked with accountability and with discipline the only purpose of showing this or sharing this episode with you is that my suggestion to you as colleague teachers that whenever such incidences happen in your classes and I am sure there will be at least one incident every semester or every year that would be happening please don't just ignore it or forget it try to make a description of that episode share it with your own students share it with your colleague teachers I think these are very very enriching experiences which make our life as teachers far more fruitful so sorry for this digression and we'll get back to our technical stuff back again so we go back to C programming okay we discuss file processing in C so far we have seen the scan f and print f functions for basic input output but if I want to actually handle a file all by myself not standard input standard output how do I do that so first of all we understand the basics of a file as seen by a C program for a C program a file is defined through a special pointer called file star so just as we have in star float star there is a type called file star which describes a file pointer which points to a file object we declare it as file star f p so f p is a variable just like I have integer variables and float variables I have a variable called file pointer for this files any file that I use I have to open that file I have to read or write to that file and I have to close that file a file may contain millions of bytes the beauty is that in C I have functions which are capable of positioning inside a file at a particular byte address and is capable of reading or writing at that position this is exemplified through this small explanation here so first of all star f p will point to the file object but a position pointer which can be made to point to any byte position in the file for random access files once I position the pointer and we shall see how we can position the pointer operating system or C does not automatically position the responsibility is ours so we assume let's say the file has one million bytes and I want to position the pointer at exactly one thousand two hundred and fifty third byte I can actually do that once I position the pointer then I can read or write as many bytes from that position as I want and that is what gives me the extraordinary capability of random reading or direct reading and random writing or direct writing in short either I can process a file sequentially in which yes I will keep reading bytes one after another all I can process the file by random access so where I position a pointer I actually assign a proper value to the pointer and then I can read or write as many bytes as I want what we are going to examine is some functions in C which permit us to do that these are the modes of file opening as I told you I must open a file first a file may already exist in which case I can open it for reading data from or appending to it or read write both a file may not exist but when I open it for writing a new file is created a file may be text file such as the ones in which we handle data through scan f and printer or a file may be called a binary file binary file does not mean that there is a gibberish binary data inside there could be text data inside but the general implication is that if I open a file as a binary file and create a file as a binary file normally the contents of that file cannot be directly examined by an editor so I might have some internal storage reflected into the bytes that I write in such a file these are various modes these modes are used along with the open function cause so whenever I open a file I can give a flag which is R which simply says input file for text RB stands for binary W for creating output and WB for writing or creating binary file so text in binary are the two types of files if you so wish to call them and these modes are W R plus R plus B or RB plus similarly W plus W plus B or WB plus A stands for appending to a file remember I mentioned that when I open a file for writing there might exist a file and I can open a file for IO so that I can randomly go to any position and replace existing data by something else by writing there but ordinarily I will take a file of some records and I might want to add records at the end and that is called appending so the mode that I will use will be called an append mode sequential files in C are very commonly used and these are exactly like the ordinary sequential files that we have seen for example whenever we prepare a file to contain data whether it is numerical data for matrices or whether there are records of the kind that we just saw we will generally treat them as sequential files where we will read or write record by record this data is read only in a sequence and therefore the position pointer is essentially automatically managed by the underlying function library we don't have to explicitly set position okay whereas so most text files are treated as sequential files and formatted input output is usually used for text files I am here listing all the IO library functions f open so I give a file name which has been declared as a file pointer type the f open function call will open a file f close function call will close a file if I say fp is equal to f open my file dot text comma r then this will actually open a text file for input or for reading similarly I can use that f close call as f close fp we have seen scan f functions scan f works with std it but if I say f scan f then the f scan f function as the ability to read from a file please note that this is not redirection one reason for necessity for such function cause is that I can redirect only to std in or std out but suppose I have a processing requirement where some data is to be read from one file simultaneously some other data is to be read from another five simultaneously some other data is to be read from third five there is no way redirection can help this redirection redirects only one standard file either std in so std in in this case so in I will have to necessarily open multiple files and read data from that suppose I want to read data which is formatted and I want to use scan f how will I do that when there are multiple open files that is where I use f scan f I have already indicated that I can use s scan f this is a function call way which does not apply to data in a external file but it applies to a data in a string so if I have s as an array which contains a string then whatever scan f would have done on the input record given either from keyboard or from a file it will do the same thing to the contents of the string these are very powerful functions exactly the same fashion I have print f I have f print f which will print formatted output to the named five which is indicated by fp and I have s print f which will actually use the format recipient to create an output inside a string which then I can combine with other strings and output so it it permits variety of options for me to choose from I already told you get s which is get string the f get s fp I have not indicated here but it will get from a particular file get s will get it from a from a std in similarly put string and f put string this is the reference I was mentioning to c++.com this is a this is a site which actually describes a whole lot of details useful details about c++ but inside that reference there is a c library and inside the c library page there is std io that is standard io in that you will find very complete description of all functions of the c library last but not the least for random access open and close will be used will be done using similar functions but setting up of a pointer is done by a seek command f seek the word seek comes from the original disk drive if you recall that diagram where on whichever track I have data of the disk I have to move the arm to that track that is called seeking the track so since seeking is some kind of positioning although there the positioning is only on the track here we are seeking a specific point in the disk or a bytecode f seek is that function call so when I say f seek it means that take my file fp which I would have already opened use this offset and push my file pointer to that offset starting with that offset when's okay I will in fact I will leave it to you to figure out what exactly how exactly do you use this f seek I have some example I think here which we shall see now here is reading from a binary file so I want to read data from binary file so what I say f read ptr ptr is pointer to a block of memory with a minimum size of size into count bytes size is the number of bytes in each element to be read so please note I am talking about now blocks like records so I have one record which is let's say 58 bytes long it depends upon the components of the record and I want to read a block of memory okay with this size size into count so 58 byte records I want to read 10 such records so size will be 58 count will be 10 ptr is the pointer that means the starting position of this block of bytes and what is stream stream is nothing but our fp which is the name of the file so what this particular f read will do is that based on the ptr remember what is ptr ptr is the position inside that file obviously to set the pointer I must use the seek command to set the pointer appropriately once the pointer is set from that point onwards so many bytes will be read in one shot by this f read comma how many bytes size into count this is an extremely powerful system call which permits us to do a random access how do I write to a binary file this is an example the command is f write ptr size count and stream exactly the same way as f read was so here is an example int main file star p file I am describing a file pointer p file now I am describing a character array care buffer no size mentioned equal to character x comma character y comma character z incidentally we have not discussed this feature earlier but arrays when they are declared can also be initialized by giving individual values for individual elements and putting the entire collection in process like this this can be done for numerical value arrays float integer arrays this can also be done for character array please note that the size of the array is not declared here so this buffer 0 will be given value x buffer 1 will be given value y buffer 2 will be given value z and since it is a character array in all pointer probably will terminate now all that I am trying to say is I open a file which I call my file dot bin this is entirely my choice any name that we give the word dot bin does not signify anything to either operating system or C it is only my way of saying that this file is probably containing only binary data and I open it for writing in a binary mode now notice what I am doing write buffer comma size of buffer comma 1 comma p file so what I am doing here size of buffer size of is a function in C which gives me the size of any structure buffer is an array I do not know what is the size of buffer okay the size of this array could be 3 4 5 whatever it is as per the internal convention size of buffer will return with those many bytes let us say there is 3 bytes 5 bytes 7 bytes 4 bytes in this case it should be 4 1 is the count so I am writing exactly 1 unit of 4 bytes at the position indicated by sorry I am writing this information this is the block of memory to be written and I am writing it in p file where will it be written at the current position of the pointer since this is the first position this is the first right statement it will get written there I just write this and close this file later on by another program if I open the file and read the first block that I have written I will get exactly these values so this is how simple it could be for reading and writing some explanation about binary files as opposed to text files the data stored in binary files cannot be seen through normal text editors for example fingerprint files for example digital photographs or audio video recording second even structured records of useful information may be stored in internal binary form in a file if we so wish so floating point numbers okay there are let us say there is an array of 10 floating point numbers so instead of converting them into printf or S printf and taking a string and then storing that that entire formatted string in my file and then calling it a text file again having to spend time while reading it to reconvert back into internal format I can simply do the following I can take the array of floating point numbers and directly write entirely as it is inside a file I am sure that whenever I read it back into the same structure I will recover the exactly same representation etc. etc. such files will have to be declared and processed as binary files and it is preferable to have fixed side records inside those files so record is not merely record on a text file as we saw in case of those mid semester marks that is a visible record which has visible fields called text which is either alpha numeric or just numeric or whatever however inside binary files the total information that you write corresponding to some entity will be called a record and that record will have certain size what is being stated here is it is best to have fixed size records there is an example with which we illustrate this using some sample data of students this is a different sample data this data I have created at text file let us say what I have is name a roll number and I don't know these may be marks or some some third value some numerical value there are six values Millen, Sony, Ranjit, Asha, Ashita, Vinita arbitrary names and some arbitrary numbers have been given what do we want to do with these we want to create a binary file and write this data first of all we look at the definition of a struct student info observe that we have not discussed structure so far we are going to do that a bit more elaborately tomorrow morning in the first session when we discuss structures and union but I thought it appropriate to introduce this notion right now itself first of all it is not a difficult notion and secondly it is important for us to see how it is used in the case of reading and writing to binary files where we want to put conglomerate records information about one entity in one shot as a binary data so look at this I have defining here care name 31 care roll 9 integer hostel float marks character grade notice that the input file that I have prepared seems to have only three values apparently the first one is name apparently the second one is roll number perhaps the third one is hostel which is indeed the case hostel 3, hostel 1, hostel 11 but there are no marks and there are five marks there is a five elements for marks because there may be five evaluations quiz test assignment project whatever and finally there is a grade which is a three character grade now this all data for each student has to be described as a single group and I will have how many such data as many students as I have now observe that individually each of them is a normal variable but when I define this struct student info this student info this is a special definition so let us see what this struct student info mean first of all a structure defines a new type of data value which denotes a collection of several data items and what is it am I defining an actual conglomeration of data no it denotes a collection so the name of the structure shown in the definition is really an abstract data type so what I am creating is just like there are standard data types int float I know int means 4 bytes I know float means 4 bytes I know care means 1 byte similarly now student info is a new type that I am creating so what is student info student info is a structure is a description of a structure how many bytes does it occupy well as many bytes as the sum total of bytes occupied by individual components that is now the type remember whenever I have a type I have to declare variables or arrays of that type for actual memory allocation to happen with the definition of struct that we just saw we can declare variables of this type in our program for example having defined student info as a structure in my program I can say struct student info x struct student info is a composite word it means the data type which I have defined artificially called student info it is almost similar to saying float y int z or whatever struct student info means x is now a new variable which I am defining but it is not a simple variable holding an integer or floating point value rather it holds the complete structure which I had defined now this structure has components this structure had a roll number name whatever whatever whatever but once I define a variable first of all the compiler allocates enough memory to this new variable of an abstract type called student info such that all components which were described in the structure are available for referencing as a part of this x which is the new variable how do I reference different components of x now well these are referenced by saying for example x dot hostile which will represent an integer value remember roll is a character array okay we had said that so many characters constitute a name individual element of that character array will be referenced by saying x dot roll 2 so dot is the symbol used to say left hand side is a variable of that type structure right hand side is a particular element that is being referenced and x dot hostile now can participate in any expression where an integer variable or value can participate x dot roll 2 can participate in any expression where a character you can participate similarly if I have to pass an array to some function or name use the name of an array then x dot roll will be that name which I will use in that context here is an example int main struct student info s so please notice I have defined student info structure I am defining s as one variable I hope to use this variable to store the values of information about one student remember my input file is still a text file I have to get that data and hopefully I want to create a database of student somewhere so to read one record and store it somewhere I will use this s variable I might want to read records of all students store them in an array here is an example of defining an array of structures struct student info student list 100 so each element of student list is neither an integer nor a float nor a car but each element is actually a structure so consequently just as I have s student list 0 is some similar to s student list 1 is similar to s they all are of the same type student info now this is a program which I am writing to decide this is a database program by the way so an option which is a character variable it is to be read I will describe what that option is I am describing two character pointers star n and star r I now define integer rake size which is the record size the objective of this rake size variable is to denote the total number of bytes that will represent the total data about one student since a student is defined in terms of that structure the rake size should reflect the information about that structure similarly I have a file whose file name I give as batch input file dot text so this is the file that you have got please remember that at the time of definition of an array such definitions may be possible what is the rake size? rake size is equal to size of s remember size s is a variable defined as structure student info consequently this size of operator will return the total number of bytes allocated to the structure s which I have defined of the type student info let us go back a couple of pages and see exactly what this would be garr name 31 the first element is an array of 31 elements the second is an array of 9 elements both are char so totally I have got 40 bytes so far in hostel it would typically be 4 bytes so I have got 44 bytes float marks 5 now this is float so every element will be 4 bytes there are 5 elements in this array total of 20 bytes char grade 3 the 3 elements so 3 bytes consequently if I declare a variable of the type student info like s then the total size of the number of bytes occupied by s will be equal to some total of this and that incidentally is what will be given to me by this size of operator here is a function that I write void print student struct student info s so I pass this struct as a parameter I expect to get it and I say serial number it is a artificial serial number I print for the serial number the name roll number and hostel of the student and if I have marks I print the mark this is merely a function to actually print the details of a student whose data is stored in that structure this is the main program which we are discussing and I was showing you that if I have this rake size equal to size of s what will it return so it will return the sum total of bytes allocated to the actual variable s this variable is a structure s itself does not directly stand for any individual value but components of s do so look at what I am doing now I open a file by giving the file name which I have already assigned in a value and I say it is input that is for reading and I open this file I do the following I use the f scan f to read from this file a number remember the file format that I gave for input the first is the total number of students then I say I print the data of so many numbers now I set up a check if fp is not equal to null that means the file was actually open please remember that the f open command will try to open a file if for some reason I cannot open a file there is no file for example I have forgotten or I have given I am in the wrong directory when I open the file so I may get an error if I get an error while opening the file pointer return is null you will notice that similar thing happened in some of the function that we saw earlier in fact this is a standard practice in all c functions which return a pointer if things succeed they return a proper pointer if things do not succeed as we wanted they will return a null pointer same thing happens in this case so if fp is not equal to null that means everything is alright file was open now what I do for i equal to 0 to n n minus 1 that is 1 by 1 I read the data of all students and I am using f scan f notice that I have opened a file each line is a text line so I want to read it as if I am reading it using scan f but I am using f scan f to read from that file percentage percentage percentage why because I am reading a string another string and a numerical value this was a question that somebody had raised I can read two strings I want to read them into which variables I want to read them into two arrays string arrays which is name and role but s dot name and s dot role because s is the structure please note that name and role have no separate existence in fact if there is another array defined as with name then I might be referring to that if I do not use s consequently this particular f scan f percentage percentage percentage d will read values of three variables the first one is a string the second one is a string and the third one is a number the first string will be read into the array which is referred to by s dot name please note that s dot name means the complete name this is called type casting as I had explained to you I convert it into a character pointer because it the parameter expected here is a character pointer similarly cast star s dot role and for s dot hostel which is a numerical value I simply put that pointer that is the address computing ampersand since I am not giving as input marks at this stage I will set marks to all zero maybe at the beginning of the semester no marks have been awarded there is no grade awarded so maybe I will put star star in the grade notice that it is a three element array so I am putting star star in the grade normally my grades are a a a b a c c c d b b etc they are actual grades a star star later on will mean that this student has not been awarded any grade so this is the how I am reading data for one student putting it into various components of that structure assigning zero values for marks because there are no marks and assigning an artificial star star grade by executing this particular set of instructions for I equal to zero I got the first student data then I equal to one I got the second student data and so on when I finish reading all the students data I have got in the array student list I notice the simple assignment all these statements collect different components in s I use the print student function which I have written to print that data now I take the entire structure in this variable s and assign it to ith element of an array of structures so after assembling all the components I put all of them into this array finally I close the input file this completes the reading let us now look at okay this else refers to if there was file pointer return was was null now I am creating an output binary database file what is the size of each record the size is rec size remember I have already calculated rec size using the size of operator and giving it a structure variable s as a parameter so that I know exactly how many bytes I should write per record creating of database file is so simple I open a file I call it db star db so db is the name of the pointer that I give f open db file wb w is for writing b is binary file simple so I have opened this file for writing and I know that it is going to be a binary file look at what I am doing for i equal to 0 to n minus 1 meaning for all the students that I have I take the data about ith student from the array assign it to this simple simple structure variable s remember s also means roll number name marks etc which are all been set to 0 and all that I do is f write and s size of struct student info comma 1 comma db db is the file name it will write one unit of this structure and what is the size how many bytes size of this so size of struct student info and what values from my memory I wanted to write the memory that is pointed to by s so I have address of s notice that I have extracted the actual values to be written in s therefore when I give this command a record is written in the file when I write a record by the way the position pointer which I mentioned initially is automatically advanced to the next position so when I execute this in an iteration one by one I will write records in my file consequently at the end of this simple loop I would have written all the records having written these records I can now have some code to read the data about any particular file here is the main program now these are all functions main program says struct student info s long int db file pause remember now I want to read randomly so I am now creating a position variable it so happens that the normal int is not adequate so long int is prescribed this is like a pointer but not a pointer to an array or any variable this is the file position pointer I am going to manipulate it based on which student I want to read I say integer I serial number rex size test number etc I have float test marks character db file equal to student db dot min so student db dot min is the name of the file which I have used again rex size size of s etc notice what I am trying to do now remember that I have written these student records first record which was given I call it serial number one I wrote it in the first position second in second position third in third position although there is a roll number in each record as well I am concerned I am actually counting the position of each record by some serial number serial number one means first record serial number two means second record serial number three means third record and so on consequently if somebody wants to retrieve the record of a student I will ask him at what serial number the data was given suppose he says it was fourth well I will read that serial number using a scan f purpose is that for the fourth student somebody my t has given marks which I want to allocate and write back into the disc so I will collect the test number and test marks to be updated and I will read the test number and test marks in these two variables this is a very comprehensive functionality program by the way so you may want to read it again notice now what what I am doing in this code I open the db file notice that the file has already been created so I open it for reading and also for writing this is really called an update operation I do not want to write arbitrarily there is no point the objective is that there is a student record somebody gives me the test marks for that student which do not exist originally all that I want to do is read that student's record modify the values of the marks by taking the new values that I have got and rewrite in that place itself in that place itself is important because later on whenever I read that student's record again I should get the updated value see how easily it is done first of all I position I calculate the position of the file pointer size of struct student info into sno notice that sno starts with zero so I have a zero as student first student second student etc. suppose I am looking at the fourth student I will simply multiply that fourth student by the size because I know for every student I have written this size so I know exactly at what point the next student will be this gives me the db file pass now I use the fc command which I had explained earlier command means function so what does fc do fc says for this file pointer fp seek set that is set the position that pass in the file that I had shown to you at a position which is given by db file pass so if I am wanting to update the data of the fourth student by these two statements in that binary file the pointer file pointer will be set to the beginning of the fourth student's position now I simply do an f read for this fp file pointer I read one unit of the size of one student's information and store it in the structure variable s I will print that data now I know that the marks have come which I have read so I will set up the marks into the appropriate array element of s dot marks and now I am ready to update the database file this fc command merely reconfirms the seek set to the previous position that I had commanded I will tell you what happens when I have set up file pointer at a particular position and I give an fc I have read so many bytes I don't want now my file pointer to point to that position because what I want to do is come back and rewrite this block itself so this fc fp seek set will set that pointer to the previous value and now I f write f write is very simple into that into the file of this information and what information and s the same data which I have read which I have modified by adding the marks I am rewriting it I will confirm the changes in the file by reading it again so I will again say fc same file position seek set and f read again so please note this is like a verification I read some record I modified some values I rewrote it I want to check whether by rewriting when to the correct place and correct values were rewritten or not simple I reset the pointer to the beginning of that particular student record inside the file read that data print the student's information I know that everything is okay and I will close the file this then is a comprehensive program which is capable of creating a database file from some input data which is a binary file it creates chunks of records each record is actually a complete record containing information about a student which has several components all these components are described as a part of structure we saw how a structure is defined having created a database file around serial numbers as an artificial unique positioning identifier in the database strictly speaking this is not correct and in today's lab I have indicated a discussion session that if instead of a serial number if somebody tells me look this is the roll number of the student get me the data how will I handle it I can handle it by sequentially reading all records comparing the given roll number and fighting out whether that is the roll number or not but I would like a direct addressing mechanism which I have got created artificially using a serial number in any case what we saw in this program is first a database file is created a binary file I can now get any student's data suppose marks are to be updated I can read the marks for that student given the serial number I know how to open the database file I know how to go to the correct position set the file pointer read exactly those many bytes of data depending upon the size of the structure for that student into my memory modify values here I am modifying a marks but I could even say change in anything whatever and then I am rewriting it exactly at the same position and then verifying that I have rewritten in short what we have done in the last half an hour is really to understood a very rudimentary way of creating a database accessing the database accessing the database record a randomly reading that and updating it is this problem that we have tried to solve through our understanding of file processing in short in this session we saw simple IO which is can f and print f for text file we also saw how direct text files and binary files can be handled meaningfully to permit us to do our desired operations on data particularly when I want to organize data as some kind of a database file where I have and this example was only six records the problem that I have asked you to look at in the lab today does not deal with this data but it deals with the data that you get from that mid semester file so I have asked you to do the following treat that as the basic input that you have got and create a database file for those 800 students you may take a serial number which is there in the input file itself treat that as the key role number name etc etc you can store you may additionally want to keep some space in that structure for future marks which may come there is a lot of imagination that you can do please try to write that program incidentally to read that data meaningfully using c because you would not be using ox script I have included in the lab today a sample program which was written by one of the students I think I mentioned it so enthusiastic I think Ketav Mehta was his name so when I discussed this particular problem and ox within one day he came back saying sir I have written a program to calculate the batch wise totals and averages and so on so why I have included that program for two reasons one to show you what enthusiastic students are capable of doing he wrote that 300 line program in a single day and submitted it to me you may not be able to use that program for the purpose of the lab problem which requires you to create a database file but you can use much of the statements in that program to read the data from every line to break it up into different parts which is what he is doing of course you will have to study that carefully and modify it wherever you want so use portions of that program to read the data use the ideas given in this particular program to write into a database file that is your exercise today I think with this we are close to this session there are two more slides okay this is just print all database records in the main program I am actually reading all records from the database one by one because there were six records this is not correct I should be reading all records using checking whether the file has ended or not so it could be more complex thing this is a simple example but effectively I read the structure one by one and I print the students data so that is it for this session thank you over and out