#include "string.h" void StrAssign(sstring * st, const char * ch) { size_t size = strlen(ch); st->s = (char *) malloc (sizeof(char) * (size+1)); if (!st->s) { fprintf(stderr,"Failed to malloc!\n"); exit(EXIT_FAILURE); } strncpy(st->s,ch,size+1); st->length = size; } void StrCopy(sstring * st, const sstring * sp) { if (!sp->s) { fprintf(stderr,"Empty string!\n"); exit(EXIT_FAILURE); } StrAssign(st,sp->s); } bool StrEmpty(sstring * st) { if (!st->s) return false; return true; } int StrCompare(const sstring * st, const sstring * sp) { int count = 0, i; if (!st->s || !sp->s) { fprintf(stderr,"Empty string!\n"); exit(EXIT_FAILURE); } for (i = 0; st->s[i] && sp->s[i]; i++) { if (st->s[i] > sp->s[i]) count++; else if (st->s[i] < sp->s[i]) count--; } if (st->s[i]) { i++; count++; } else if (sp->[i]) { i++; count--; } return count; }