Hello im an 2nd year university student, and i am stuck on an assignment.
I am supposed to store the length of the string in the zero'th element of the array, and the remaining characters after. No null terminator is used in this setup. My assignment is to implement this style of string library in C.
Im not expecting for someone to do the assignment, but i have been having a very hard time understanding the how to use strings and array pointers, so you can probably tell i would have difficulty to this.
I have these guide lines:
1) The functions ps_cat, ps_cmp, and ps_cpy should mimic the corresponding routines strcat, strcmp and strcpy in the C standard library.
2) ps_set copies a null-terminated C string into a pstring
3) ps_put should output the pstring on stdout.
4) ps_set and ps_cat should make sure that no overflow occurs, and either abort or truncate the string. Make sure you document your choice for each function.
You should use the following declarations:
and i have an example program:
#define PSTRING_MAX 126
typedef char pstring[PSTRING_MAX+1];
void ps_cat(pstring dest,const pstring src);
int ps_cmp(const pstring a, const pstring b);
void ps_cpy(pstring dest,const pstring src);
void ps_put(const pstring);
void ps_set(pstring dest,const char *);
which gives the following output:
pstring a, b;
printf("%d %d %d\n", ps_cmp(a,b),
I am very lost, and don't know how to tackle such a program, i understand what the example program is doing, but don't know how to write my own ps_cat, ps_cmp, and ps_cpy functions.