Raspberry PI switching from Soft Access Point to WIFI client
There are a few compiler errors that may not have show up for you, the first major compiler problem is that read is a basic function in C input and output so the variable declaration ssize_t read; should be changed to something like size_t readsize. It might be good if you compiled with the -w flags to add warnings to the compiler error messages.

The second problem I see is that you might have compiled this with a C++ compiler rather than a C compiler, a strict C compiler will not recognize the function readline() in a strict C compiler fgets() should be used instead. You will have to make the variable line an array of characters.

char line[BUFSIZ];


The symbolic constant BUFSIZ is defined in the include file stdio.h.

    fgets(line, BUFSIZ, fp);


Overall it would be better if main() was a short function that called other functions, it is currently too complex (does too much).