Problems :error C2664, datatype

Hi!
(I think the problem are about pointers, only a tips, but in fact i have no point what the problem can be)

I wondered if someone could help me with this file, the error massage I get when I compile the project is: error C2664: 'bokstav' : cannot convert parameter 1 from 'char *(__cdecl *)(char)' to 'char *'

What is that mean? And how can I fix it.

The file is suppose to convert Morse-code to Swedish text or English and contrary. The language in cout is in Swedish.

I am a beginner in programming in C++, so please use a easy understanding language.

If there is any questions about anything else just text me (e-mail or in this forum).

/ Puckosmucko, pleas help me.







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <iostream>
#include "iodos.h"
using namespace std;
//------------------------------------------------------------------
char *tab[] = {".-",    "-...",  "-.-.", "-..",  ".",    "..-.",
               "--.",   "....",  "..",   ".---", "-.-",  ".-..",
               "--",    "-.",    "---",  ".--.", "--.-", ".-.",
               "...",   "-",    "..-",  "...-", ".--",  "-..-",
               "-.--",  "--..",  ".--.-",".-.-", "---." };
//------------------------------------------------------------------
	
// Function definition from text to morse-language

	char *kod(char c) 
{
  if (c == 'Å' || c == 'å')
    c = 'z'+1;
  if (c == 'Ä' || c == 'ä')
    c = 'z'+2;
  if (c == 'Ö' || c == 'ö')
    c = 'z'+3;

  if (c>='A' && c<='Z')
    c = c -'A' + 'a';
  if (c >= 'a' && c <='z'+3) // om c = från a(A) till ö(Ö)
    return tab[c-'a'];
  else if (c == ' ' || c == '\t')
    return " ";
  else
    return "";
} 

//--------------End of function-definition-------------


// Function definition from morse-language to text
char bokstav(char *s)
{
  for (int i=0; i < sizeof tab /sizeof tab[0]; i++)
    if (strcmp(s, tab[i]) == 0) /* kopierar en sträng från tab[i]		till s om utrycket strcmp(s, tab[i]) == 0  */ 
    {
      char c = 'a'+i;
      if (c <= 'z')
        return c;
      else if ( c =='z'+1)
        return 'å';
      else if ( c =='z'+2)
        return 'ä';
      else if ( c =='z'+3)
        return 'ö';
    }
  return '?';  // markerar felaktig morsekod
}
//--------------End of function-definition-------------  



int main()
{
dos_console();


char in_mat;
cout << "Vad vill du göra?\n(1)Översätta till morse\n(2)Översätta från morse\nVal: ";
cin >> in_mat;

if (in_mat == '1')
{ 

char m[500];
	cin.getline(m, 500);
for (char *p=m; *p; p++)
    cout << kod(*p) << ' ';
  cout << endl;
	
}

else if (in_mat == '2')
	
	cout <<  char kod[10];
  while (cin.peek() != '\n')
  {
    cin >> kod;
    cout << bokstav(kod);
    if (cin.peek() == ' ')
      cin.ignore();
    if (cin.peek() == ' ')
    {
      cout << ' ';  // nytt ord
      cin.ignore();
    }
  }

return 0;
}


On line 80, remove the cout << part.
It's that all?
That doesn't work. Now I get the errors:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
Compiling...
File01_SourceFile.cpp
c:\documents and settings\viktor sundlin\mina dokument\visual studio 2008\projects\projekt_morse\projekt_morse\file01_sourcefile.cpp(82) : error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'char *(__cdecl *)(char)' (or there is no acceptable conversion)
        c:\program\microsoft visual studio 9.0\vc\include\istream(1144): could be 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char *)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program\microsoft visual studio 9.0\vc\include\istream(1146): or       'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program\microsoft visual studio 9.0\vc\include\istream(1148): or       'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char *)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program\microsoft visual studio 9.0\vc\include\istream(1150): or       'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program\microsoft visual studio 9.0\vc\include\istream(155): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_istream<_Elem,_Traits> &(__cdecl *)(std::basic_istream<_Elem,_Traits> &))'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program\microsoft visual studio 9.0\vc\include\istream(161): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program\microsoft visual studio 9.0\vc\include\istream(168): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::ios_base &(__cdecl *)(std::ios_base &))'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program\microsoft visual studio 9.0\vc\include\istream(175): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::_Bool &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program\microsoft visual studio 9.0\vc\include\istream(194): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(short &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program\microsoft visual studio 9.0\vc\include\istream(228): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned short &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program\microsoft visual studio 9.0\vc\include\istream(247): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(int &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program\microsoft visual studio 9.0\vc\include\istream(273): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned int &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program\microsoft visual studio 9.0\vc\include\istream(291): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(long &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program\microsoft visual studio 9.0\vc\include\istream(309): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(__w64 unsigned long &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program\microsoft visual studio 9.0\vc\include\istream(329): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(__int64 &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program\microsoft visual studio 9.0\vc\include\istream(348): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned __int64 &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program\microsoft visual studio 9.0\vc\include\istream(367): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(float &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program\microsoft visual studio 9.0\vc\include\istream(386): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(double &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program\microsoft visual studio 9.0\vc\include\istream(404): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(long double &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program\microsoft visual studio 9.0\vc\include\istream(422): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(void *&)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program\microsoft visual studio 9.0\vc\include\istream(441): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_streambuf<_Elem,_Traits> *)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        while trying to match the argument list '(std::istream, char *(__cdecl *)(char))'
c:\documents and settings\viktor sundlin\mina dokument\visual studio 2008\projects\projekt_morse\projekt_morse\file01_sourcefile.cpp(83) : error C2664: 'bokstav' : cannot convert parameter 1 from 'char *(__cdecl *)(char)' to 'char *'
        There is no context in which this conversion is possible
Build log was saved at "file://c:\Documents and Settings\Viktor Sundlin\Mina dokument\Visual Studio 2008\Projects\projekt_morse\projekt_morse\Debug\BuildLog.htm"
projekt_morse - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Line 80 doesn't make much sense. kod is a function. You cannot redefine it as a char[].
1
2
    cin >> kod;
    cout << bokstav(kod);


These lines don't make sense at all. In the first one you are trying to pass a kod (a function) to std::cin, and the second you are passing a function to another function.
Haven't solved it yet. But that is probably because I haven't enough skills. I think pointers is coming in programming C (c++), so I close this topic.
Topic archived. No new replies allowed.