I have to write a program that is using polish characters. The problem is with function in a function, both have the same one of variables(like a(int smth) b(int smth)
, this smth
is the same one that had been used in both)
I have open_dyk
function in main. There's text in the file, something with pl characters like grzegżółka
in the first line, but it doesn't matter how many times I launch the program, it gives me huge A and random doubled character like yy 22, etc.
struct dyk{
wchar_t line[200];
struct dyk *next;
};
typedef struct dyk dyk;
dyk* add_to_bottom(wchar_t *buf, dyk *head)
{
dyk *current_node = head;
dyk *new_node;
while(current_node != NULL && current_node->next != NULL){
current_node = current_node->next;
}
new_node = (dyk*)malloc(sizeof(dyk));
wcscpy(buf, new_node->line);
new_node->next = NULL;
if (current_node != NULL) {
current_node->next = new_node;
} else {
head = new_node;
}
return head;
}
void print_all(dyk *head)
{
dyk *current_node = head;
while ( current_node != NULL) {
wprintf(L"%s ", current_node->line);
current_node = current_node->next;
}
}
void open_dyk(char name[100], dyk *head)
{
wchar_t buforek[100];
FILE *dyktando;
dyktando = fopen(name, "r+");
if(dyktando == NULL){
wprintf(L"Błąd otwarcia pliku!\n");
}else{
while(!EOF){
add_to_bottom(buforek, head);
}
print_all(head);
}
fclose(dyktando);
}
main function consist:
system("chcp 852");
setlocale(LC_ALL, ".852");
dyk *show;
show = (dyk*)malloc(sizeof(dyk));
open_dyk("farm.txt", show);
As I said a bit earlier, expected result should looks like this:
grzegżółka?
ź ż
Actual results look like this:
A11
(or other variations like AYY, Abb, etc.)