I've tried using the method indicated here but I'm unable to pinpoint each character from the array "buffer". My end goal is to make one array for each sentence with one word in each row so I need to first know where each character is.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
#define LENGTH 100
bool input(char *file_name, char *phrase)
{
FILE *file;
bool file_valid;
int i, j, k, l;
file = fopen(file_name, "r");
if (file != NULL)
{
file_valid = true;
while(fgets(phrase, LENGTH, file))
{
printf("%s", phrase);
}
printf("\nThe file was loaded succesfully.\n");
fclose(file);
}
else
{
file_valid = false;
printf("\nWe couldn't find a file with the specified name. Closing program.");
}
}
int main()
{
char file_name[20], phrase[LENGTH];
int i, j;
printf("Please introduce the name of the file: ");
scanf("%s", file_name);
input(file_name, phrase);
return 0;
}
There are some variables and headers that aren't necessary atm but I will be using them later on.