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 && subs != ' ' && subs != '\n')
{
printf("%c", fullSub[i] = subs);
printf("%d", strlen(fullSub));
i++;
}
fullSub[i] = '\0';
printf("%d\n", sizeof *fullSub);
//free(fullSub);
}else{
fprintf(stderr, "Failed to open file '%s'!\n", filename);
}
for(i=0;i<strlen(fullSub);i++)
printf("%c", fullSub[i]);
free(fullSub);
}
Thant's my current code, but I am having some problems, still. Strlen returns 6..? And I need to know how to jump to the next line? Would I just increment 'i' when I reach the newline character and it'll jump to the next line?