Worth 1 mark
https://buytickets.at/comp1511unsw/1741784
Access code is COMP1511
Email course account if you can't attendchar[]
Notice the \0
at the end! This means that C will know when it reaches the end of the array
Note the # of elements, and don't forget the \0
"Jake!"
"
to wrap the string literalUsed to assign strings to char[]
easily:
char name[] = "Jake Renzella";
fgets()
-> reads a stringfputs()
-> prints a stringstrlen()
-> gives us the length of the string (excluding the \0
).strcpy()
-> copy the contents of one string to anotherstrcat()
-> join one string to the end of another (concatenate)strcmp()
-> compare two stringsstrchr()
-> find the first occurrence of a character
#include <string.h>
int main(void) {
char name[MAX_LEN] = "Jake";
strcpy(name, "Mr Otterington");
}
^ Remember we can't reassign like:
name = "Mr Otterington";
.
operator to access the field once we initialise a struct!We can have arrays of type (char, int, struct, enum)
students[1].name;
to access element 1's name<type> <identifier>[<rows>][<cols>];
int my_grid[5][5];
my_grid[2][3];