char sv1 = 'a';
char greeting[] = "hello";
read(
&sv1, // sv1 is a char, so &sv1 is a pointer to the char
greeting // greeting is a pointer to an array of char
);
error C2665: 'read' : none of the 2 overloads could convert all the argument types
1> d:\grprog\blablab\some.cpp could be 'void read(char *,char *)'
1> while trying to match the argument list '(char, char)'
this is with:
read( &sv1 , &sv2 );
here is the declaration of the function: void read ( char* , char* );
That's a really dangerous function because you have no idea how much data will be written to in1 or in2 from cin, nor how much data those two character buffers can hold.
The example does pass in a pointer -- the variable "phrase" in that example is both a character array and a pointer to the first character in the array.
The function is for a menu system we have to make for a school project.
The menu choices are to be read by two letters. So if I wanna do one thing: I could write: k t and based on alot of if sentences, I would then find the correct menu choice with this function. Problem is that in order to make sure that the two letters are understood correctly, I will have to make them to upper or to lower. The loop that is used to check these chars have a else for all the wrong inputs aswell.
Best way I could think of was to do this with pointers or by reference so that I dont have to return anything(cause then I would have to extract the data in order to get two variables from it afterwards).
reason why Im using only two chars is thats the best way I could think of to get two letters only.
I do like to use string objects mostly, but I couldnt think of a way to limit a string to only be 1 letter(or having to modify the returned data so that I get 2 variables from it). If you have any tips on how I could do what Im after in a better way, feel free to give me some tips :)
I ended up reading into a string inside the function, then add the 2 first characters inside the string that wasnt a whitespace into the char[] in the parameter, then toupper them all and going out of the function :)