Hello and welcome back.
I want to continue our discussion on some of the functions in the standard C library.
These are a lot of the functions we went through already in class.
But I wanted to remind you of.
So there are a lot of important various functions from C standard library that we have already addressed
throughout the course with all of our examples in all the stuff that we've learned.
We talked a lot about string functions right and some of them are very easy to use and some We're going
to use a lot so you should be familiar with these to use any of these functions you need to include
the header file string data each.
Everything is defined and storing data each.
We talked about strt cat stirre cat concatenates two strings two parameters it takes right to character
pointers and it will return a character pointer concatenated to the other one.
So placing a null character the end of the final string the function returns as one str char.
This searches for a string that contains a character or return a character star as well.
It's a good way to search.
We talked about this quite a bit with string cat strt compare going to compare two strings.
This is the standard way you do it it takes two pointers and it returns an integer.
We did have some examples of this where basically if you return zero the two strings are equal if return
greater than the last.
Then if you turn greater than zero that means one is usually greater in alphabetic size so if you passed
in a a string that contained a and then the second string is B it would return greater than zero because
your return would turn less than zero be case is less than B.
If you passed and B as the first parameter and see a second parameter some kind of string starting with
B or C will return greater than zero.
So you got to understand those return values that's what's important.
Or compare a copy.
This is how you can assign a string to another string Raemer strings pointers and character arrays.
You cannot assign a string directly using the assignment operator for integers and floats you can just
use the equals operators can't do that with string so you have to store copy when you want to assign
a string to a pointer character pointer or character right.
You can initialize a character array literal a string constant inside double quotes.
But after that after the initialization if you want to change it you have to use or copy stirre length.
Another important function to get the length of a string.
This returns a size t which is the integer representing the length.
All these string functions are taken pointers or character arrays as parameters.
So we need to understand how that works as well.
Other string functions Stern can't remember all the functions that add the end are a little more safe
because you don't have buffer overflows so stern can't.
The third parameters added and this will say copy or concatenate so many parameters usually the third
parameter is going to be the size of the first parameter because you don't want to copy anything larger
than that.
These functions should be utilized over the other string functions because they are safe for buffer
overflow Stern compare.
Again you're going to compare a certain number of characters for us wanting us to stern copy here the
third parameter and would probably be the Sturr length or the size of one cause you're gonna copy has
to an one but you don't want to copy more bytes and one can hold or store strt char.
This is where you can search the string for the last occurrence of a character when you noticed this
looks very familiar or similar to the star car there's an extra are here.
So instead of returning the first occurrence or return the last occurrence but you used the same way
as the other one stir stir this is going to research first string So this is a search function where
you're trying to find essentially a substring inside of a string.
Again taking two character pointers str talk.
This is the important function where you can help with parsing data strt talk takes delimiter as a second
parameter and it will look for that delimiter character any side anywhere inside the string.
So often you use something like a space or a line feed for us to.
It will break the string into a number of different tokens.
Again use it when you want to parse data usually every time you have the cost or a multiple number of
times until you will know if you're still looking for the next token that you want to find in the given
string.
We also had some important character functions all the character functions are defined in C type dot
h the character functions that we use where the is functions checking whether or not a characters in
alphanumeric or whether it's blank or whether it's a control character or digit.
There were a number of different functions there.
So remember that C type that H allows us to check for these different characters what they actually
are.
We also had some conversion functions in C type age mainly are to lower our two to oper to law or takes
a character or at will it will give the lower case equivalent of that c we had a member we had a challenge
where we converted lower case upper case in that challenge we actually added to our ASCII paper but
we could have called to oper on the character we could have said to operate on the character as long
as we included C type dot H and that we converted all lowercase to uppercase.
We had a lot of IO functions input and output.
We concentrate on reading and writing files but we also read input from the keyboard and we output it.
I'll put a data from to the consul or the screen.
So to use the most common I O functions that's all in the standard IRH each header file.
This file has declarations for the different functions as well as definitions for constants like end
of file Knol standard in standard output and standard error.
Those are all constant values.
There's also a constant for the file point file structure file that closes a function that we used to
close our streams.
It closes the file identified by file pointer and it returns 0 if the calls are successful otherwise
EOF as E-o out.
That's a function we didn't use explicitly but that will check whether or not you're at the end of the
file as opposed to comparing to a constant you can do after your flush.
This is a function that will wash all the data.
The internal buffer.
Sometimes you need to do this when you want to start over but you're basically just getting rid of anything
inside of a buffer.
We also have kids see this as reading in individual characters takes a file pointer.
We have positioned some of the position functions that gets the current file position for the file associated
with the file pointer and stores it in a position type which is defined in Stainer Deodato each as well.
We had our affricate ass.
This was reading in strings very nice reads characters from the indicated file a number of characters
open will open up a file and a specific mode read write or append using a file pointer.
Print Attwill will write data and formatted output.
It's similar to the print function it will take the arguments specified by the pointer and then use
formatted data to write.
So you can write integers doubles using format specifiers and then variables that you want to write.
We also put C which will write characters to a file put ask we'll write a string to a file takes a buffer
and a file pointer what you want to write in the file you want to write to scan half bold read data
from a file.
It will grab the input you know we'll use the same kind of format as scanner.
We'll take format specifiers and variables but this is nice.
You want to read in data separated by space.
You can use Lifescan af and you can specify the type so read it directly.
It's double's specific data types seek is going to move the position of where you're pointing to in
a file.
So you don't have to start at the beginning or the end of a file you can go directly to the middle of
the file once you see to that position your next reader right.
We'll use that position to write to or read to set position is similar to seek and that's the current
composition of the file associate with the file pointer to the value pointed to by position of pos.
We also had Actel that tells going to return how many bytes from the beginning you are based on the
file pointer.
So it's the relative offset in bytes from the current position.
Now he's beginning with the current position.
We use the FTL and one of our challenges to read a file in reverse print.
We use this probably more than any other function this was displaying output to the screen.
It uses format specifiers that are available to of arguments separated by commas.
Print up is very useful for debugging and displaying output which you do quite a bit inside of a C program.
Remove remove is a function where you can delete a file.
It takes a file name the file pointer has to be closed you can't have an open rename or rename one file
to the other file also has to be close the file cannot be opened scan at will read input from usually
the fault from the keyboard you can't change it to read input from other streams if you want to.
We also have conversion functions that we discussed throughout the course.
These Most of these functions are in the standard lib that each file header file.
We had the function this is converting a string to a flow and you pass it in a string.
We had functions A-2.
This gets versing a string to an integer and is converting a string to a long and you pass the string
and it returns either you know the return method that you're converting to.
These are very useful you often use these to convert strings to some kind of number type 8 to allow
converts it to a long long int.
But make sure you look at the standard live Haueter file for more conversion functions.
We had our memory functions are dynamic memory allocation functions.
These are really important dynamic memory allocation is important because it's much more efficient.
You only utilize the memory that you need to.
You don't create static data because your program to be much more flexible.
All these functions are included in side standard lived each.
We talked about C Alec seok is a great function where you can allocate a certain size and that will
be multiplied by N.
So you can specify the data type as well and multiply it.
The nice thing about seem like it initializes your data.
So it's really preferred over Mallick.
We have our free function which will delete the memory.
All of this memory is going to be created on the heap so we'll be around a lot longer but it's up to
you as a programmer to manage this memory.
You always want to free your memory after you're done using it because memory is a scarce resource.
In other programs and we want to use that memory so always call free after you do see Alica or Mallick.
Malik is the simpler version of creating memory.
It doesn't actually initialize any data it just takes the size as a parameter.
It returns a void star so you always need to cast it just like with see Alec to whatever type of memory
you're pointing to.
If you're pointing to.
Int or float you have to cast that.
We also have reality.
Reality is awesome because you can actually add to existing memory.
And so this way your memory can buy dynamic.
You can make it larger if you want to store more data.
Realit takes a pointer in the size it's going to keep all the data that the previous member was pointing
to.
It will allocate new memory but it will keep it so you can see.
You can actually add on to some existing memory very very useful in creating memory dynamically is really
going to be useful in all your program especially because pointers are very very important.
They're much more efficient but make sure you understand all these header files that we kind of use
throughout the course.
These are the main ones that are very very important.
We'll talk about some new ones in the next couple of lectures that we didn't get to discuss as much
as I liked but these are some important ones as well.
Thank you.