so far
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define GROWBY 4096
char ** readfile(char *inputfile, int *nolines);
void stringsearch(char *data[], int nolines);
int main (void)
{
char input[100];
int nolines = 0;
char ** filevalues;
printf("Please enter the name of the file you wish to have checked>> ");
scanf("%s", &input);
filevalues = readfile(input, &nolines);
stringsearch(filevalues, nolines);
return 0;
}
char **readfile(char *inputfile, int *nolines)
{
FILE * inputfilePtr; /* File pointer */
char ** invalues; /*array for storing values fromt he file*/
char temp[100]; /*to allocate the values from the file*/
int x = 0;
inputfilePtr = fopen(inputfile, "r"); /* allocate pointer the file data*/
while (!inputfilePtr)
{
fprintf(stderr, " Cannot open file %s, please try again>> ", inputfile);
scanf("%s", inputfile);
}
invalues = (char**)malloc(sizeof(char*) * GROWBY); /* allocate dynamic memory*/
while ((NULL != fgets(temp, sizeof(temp), inputfilePtr))) /*read values from the file*/
{
invalues[x++] = strdup(temp);
if ((x % GROWBY) == 0) /*loop for creation of space*/
{
invalues = (char**)realloc(invalues, sizeof(char*) * (GROWBY + x));
}
}
*nolines = x;
fclose(inputfilePtr); /*close file*/
return invalues;
}
void stringsearch(char *data[], int nolines)
{
int a;
char test[] = {'ed'};
int z;
char *bet[]= {0};
FILE * help;
for (a=0; a< nolines; a++)
{
int b = 0;
b = strlen(data[a]);
}
}