W następujący funkcjach pojawiają mi się takie błędy:
In file included from .\2.11.c:2:
.\letter_changer.c: In function 'char* change_letter_size(char*, letter_changer_t)':
.\letter_changer.c:16:24: error: cast from 'char*' to 'char' loses precision [-fpermissive]
to_lower((char)txt);
^~~
.\letter_changer.c:20:24: error: cast from 'char*' to 'char' loses precision [-fpermissive]
to_upper((char)txt);
^~~
.\letter_changer.c: At global scope:
.\letter_changer.c:24:18: error: 'char to_lower' redeclared as different kind of symbol
char to_lower(txt)
^
In file included from .\letter_changer.c:2,
from .\2.11.c:2:
.\letter_changer.h:8:6: note: previous declaration 'char to_lower(char)'
char to_lower(char txt);
^~~~~~~~
In file included from .\2.11.c:2:
.\letter_changer.c:24:15: error: 'txt' was not declared in this scope
char to_lower(txt)
^~~
.\letter_changer.c:38:18: error: 'char to_upper' redeclared as different kind of symbol
char to_upper(txt)
^
In file included from .\letter_changer.c:2,
from .\2.11.c:2:
.\letter_changer.h:9:6: note: previous declaration 'char to_upper(char)'
char to_upper(char txt);
^~~~~~~~
In file included from .\2.11.c:2:
.\letter_changer.c:38:15: error: 'txt' was not declared in this scope
char to_upper(txt)
Oto mój program:
Main:
#include <stdio.h>
#include "letter_changer.c"
void clear()
{
if(getchar()!='\n'){clear();}
}
int main()
{
char tab[1000] = {0};
enum letter_changer_t c;
char zmienna = 0;
printf("Podaj tekst: ");
scanf("%1000[^\n]", tab);
clear();
printf("Podaj S albo B: ");
scanf("%c", &zmienna);
if(zmienna == 'S' || zmienna == 's')
{
c = TO_LOWER;
}
else if(zmienna == 'B' || zmienna == 'b')
{
c = TO_UPPER;
}
printf("%s", change_letter_size(tab, c));
return 0;
}
letter_changer.c :
#include <stdio.h>
#include "letter_changer.h"
char* change_letter_size(char *txt, enum letter_changer_t c)
{
if(txt == NULL)
{
return NULL;
}
if(c != TO_LOWER && c != TO_UPPER)
{
return NULL;
}
if(c == TO_LOWER)
{
to_lower((char)txt);
}
if(c == TO_UPPER)
{
to_upper((char)txt);
}
return txt;
}
char to_lower(txt)
{
char *wtab = txt;
while (*wtab != '\0')
{
if(*wtab >= 'A' && *wtab <= 'Z')
{
*wtab ^= 'A' ^ 'a';
}
wtab++;
}
return txt;
}
char to_upper(txt)
{
char *wtab = txt;
while (*wtab != '\0')
{
if(*wtab >= 'a' && *wtab <= 'z')
{
*wtab ^= 'A' ^ 'a';
}
wtab++;
}
return txt;
}
letter_changer.h :
#pragma once
enum letter_changer_t
{
TO_LOWER = 'B',
TO_UPPER = 'S'
};
char* change_letter_size(char *txt, enum letter_changer_t c);
char to_lower(char txt);
char to_upper(char txt);
Deklaracje funkcji podane w moim zadaniu muszą wyglądać tak i nie mogę ich zmienić:
char* change_letter_size(char *txt, enum letter_changer_t c)
char to_lower(char);
char to_upper(char);
Co mogę poprawić w kodzie aby pozbyć się tych błędów? Z góry bardzo dziękuję