Hi,
I'll preface this by saying I am about as beginner as it gets (the "installed compiler on saturday, open first book saturday night" kind of beginner)
Basically, I have a small program that reads the current directory for any file with ".txt" and then opens and scans those files for two words and prints any string that contains those words. For ascii text documents it works a charm but for anything UTF16-32 it parses up empty.. I'm gathering from reading that I somehow need to convert my code into wide characters (or at least the part that reads the .txt files).
Does anyone happen to know a simple way to do this without re-writing the whole thing? Code is as such:
#include <dirent.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <conio.h>
int main(void)
{
DIR *dirp;
struct dirent *dir;
dirp = opendir(".");
if (dirp)
{
while ((dir = readdir(dirp)) != NULL) {
char *n;
n = strstr(dir->d_name, ".txt");
if (n != NULL) {
printf("%s\n", dir->d_name);
FILE* file = fopen(dir->d_name , "r");
char* p = 0;
char* q = 0;
char string [256] = {0};
while(fgets( string, sizeof string, file ) != NULL) {
p = strstr(string, "error");
q = strstr (string, "Fatal");
if (p != NULL ||
q != NULL) {
fputs (string, stdout);
}
}
}
}
closedir(dirp);
}
printf("Press any key to continue.\n");
getch();
return (0);
}
Any help or advice/corrections are greatly appreciated,
Thanks!