This is what I have and it works... now how do i divide the each line into two separate pieces...
for example, char *array[i] = "apple meaning of apple"
I want to divide "apple" and "meaning of apple" separately.
Can I use getline? How do i use it?
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAXCHAR 30
#define MAXLINE 10
int main(void)
{
char *line[MAXLINE];
char templine[MAXCHAR];
FILE *infile;
int i=0, count=0, len, ch;
if((infile = fopen("info.txt", "r"))==NULL )
{
perror("Cannot open input file");
return EXIT_FAILURE;
}
while(fgets(templine, sizeof templine, infile) != NULL)
{
line[i] = malloc(strlen(templine)+1);
len = strlen(line[i]);
if (line[i] != NULL)
strcpy(line[i++], templine);
count++;
}
for (i=0; i<count; i++)
printf("line %d has: %s", i, line[i]);
printf("\n");
fclose(infile);
return EXIT_SUCCESS;
}