I know my pointer game is crap. I can use them, and most situations I encounter, call for something I have done before.
I have come across a new problem with my pointers and would like to figure this out. I know I can do it another way, but in my mind it would be sloppy, and I'd really like to fully understand pointers.
Here is the code (thus far):
Code:
// Declare includes.
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Declare defines.
#define BUFFER_SIZE 500
#define MUSIC_LIST_FILE "full_music_list"
#define SYSTEM_PLAYLIST_FOLDER "/Shared/Playlists/System/"
// Declare function prototypes.
void create_files (FILE **lists, int total);
int main (void)
{
// Declare variables.
FILE *lists = NULL;
FILE *fp = fopen(MUSIC_LIST_FILE, "r");
int list_total = 19;
// Create lists and file pointers.
if(fp != NULL)
create_files(&lists, list_total);
// Exit cleanly.
exit(EXIT_SUCCESS);
}
void create_files (FILE **lists, int total)
{
// Declare variables.
char buffer[BUFFER_SIZE] = {0};
int counter = {0};
// Create enough entries for all the files.
if((*lists = malloc(sizeof(FILE) * total)) == NULL)
{
fprintf(stderr, "%s error: malloc failed\n", __func__);
exit(EXIT_FAILURE);
}
for(counter = 0; counter < total; counter++)
{
// Create filename.
sprintf(buffer, "%sPlaylist.%02d.pls", SYSTEM_PLAYLIST_FOLDER, counter);
// Create file pointer.
if(((*lists)[counter] = fopen(buffer, "w")) == NULL)
{
fprintf(stderr, "%s error: fopen failed (%s) (%s)\n", __func__, strerror(errno), buffer);
exit(EXIT_FAILURE);
}
}
}
And here is the error I get:
Code:
create_music_lists.c:49:27: error: incompatible types when assigning to type ‘FILE’ from type ‘FILE *’
49 | if(((*lists)[counter] = fopen(buffer, "w")) == NULL)
| ^~~~~
compilation terminated due to -Wfatal-errors.
Why is it complaining that I'm putting a `FILE *` into a `FILE`. The only declarations I have are for `FILE *`. Can someone please help me understand this enough to get it working?