Well, I'm trying to scan though a file 'subdomains.txt' and print out what's on each line seperately. E.g.
file contains:
Code:
this
file
means
nothing_to_you
I want each line to be printed out. Here's what I've got so far:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
void retrieveSubdomains(void);
int main(int argc, char *argv[])
{
retrieveSubdomains();
system("pause");
return 0;
}
void retrieveSubdomains() //return subdomain
{
TCHAR *filename = "subdomains.txt";
FILE *fp = fopen(filename, "r"); /* _tfopen_s */
TCHAR subs;
TCHAR *fullSub = malloc(150*sizeof(TCHAR)); /* Couldn't be bothered with using realloc to update the size, so a set size will have to do. */
short i = 0;
if (fp != NULL)
{
while((subs = fgetc(fp)) != (TCHAR)feof)
{
while(subs != ' ' && subs != '\n')
{
fullSub[i] = subs;
i++;
}
fullSub[i] = '\0';
printf("%s\n", fullSub);
//free(fullSub);
}
}else{
fprintf(stderr, "Failed to open file '%s'!\n", filename);
}
free(fullSub);
}
My code crashes... Can you see what's wrong with it? Please and thank-you.