Write to a Text File
Within this function:
I need to write pe_cnt[current] to a Text file and also pe_base. I've been trying to work with CreateFile() and WriteFile(), but unfortunately, the Text files keep coming up empty. Any help would be greatly appreciated. Thanks!
static void horiz_edge(void)
int n, ndiv5;
ndiv5 = (ia_nx - 4) / 5;
n = (ndiv5 * 5) - 1;
line_no = 0;
for (y = dm_ls >> 1; y < ia_ny; y += dm_ls)
current = line_no & 1;
pe_base = pe_ptr = &dm_pe[current ? dm_hnx : 0];
ne_base = ne_ptr = &dm_ne[current ? dm_hnx : 0];
pe_cnt[current] = pe_ptr - pe_base;
ne_cnt[current] = ne_ptr - ne_base;
Use the C standard library first before you move to O/S specific functions. They are possibly easier, and they are more portable.
Open the file with fopen(), and then write to it with fprintf(). Reading can be done via fgets() later on.
Your problem is probably that you are expecting them to be in the text file as text, but you're not converting them. Text is only useful if it is necessary that people should be able to read and modify it by hand. If you are sure you want them as text, then you can use this (Attention! Windows-based code):
maxorator, thank you for the explanation; it makes a lot more sense now. Worked perfectly :)