#include <stdlib.h>
#include <string.h>
int *rows(int n, char *M[n][n], char *s, int *pR) {
int *ind = NULL;
int nr = 0;
for (int i = 0 ; i < n ; i++) {
int j = 0;
while (j < n && strcmp(M[i][j], s) != 0) j++;
if (j < n) {
ind = realloc(ind, (nr + 1)*sizeof(int));
ind[nr++] = i;
}
}
*pR = nr;
return ind;
}
#include <stdio.h>
void update(char *fname, void (*upF)(Rec *)) {
FILE *f = fopen(fname, "r+b");
if (f == NULL) return;
Rec r;
while (fread(&r, sizeof(Rec), 1, f) == 1) {
upF(&r);
fseek(f, -sizeof(Rec), SEEK_CUR);
fwrite(&r, sizeof(Rec), 1, f);
}
fclose(f);
}
#include <stdlib.h>
#include <string.h>
void compact(List L) {
Elem *prev = NULL;
long code;
while (L != NULL) {
if (prev != NULL && code == L->code) {
int newLen = strlen(prev->str) + strlen(L->str);
prev->str = realloc(prev->str, (newLen + 1)*sizeof(char));
strcat(prev->str, L->str);
prev->next = L->next;
free(L->str);
free(L);
L = prev->next;
} else {
code = L->code;
prev = L;
L = L->next;
}
}
}