CISC 1110 10714 10715 char pointer

61 views
Skip to first unread message

Manor Perets

unread,
Dec 16, 2012, 11:06:37 PM12/16/12
to Professor David Arnow, CPP forum, Ivan Chaplikov
Hi,
Looking forward to class.
I have two problems in CodeLab that I couldn't complete as I'm not familiar with * pointer. I've read up on pointers, some, but I don't know what I should be doing any different to solve the problem.
Am I the only one not done with these two problems?
Any input would be appreciated.
Thanks,
Manor
-----------------
Write a function max that has two C string parameters and returns the larger of the two.
char max(char x, char y){ // I tried 'string' as well
if(strcmp(x,y)>0)
return x;
else return y;
}


CODELAB ANALYSIS

Remarks:
          You seem to have an error in compilation

The Council agrees that:
          You should be using: *

Want More Hints? Hear From Other Voices



COMPILER ERROR MESSAGES
CTest.cpp: In function ‘char max(char, char)’:
CTest.cpp:6:15: error: invalid conversion from ‘char’ to ‘const char*’ [-fpermissive]
/usr/include/string.h:143:12: error: initializing argument 1 of ‘int strcmp(const char*, const char*)’ [-fpermissive]
CTest.cpp:6:15: error: invalid conversion from ‘char’ to ‘const char*’ [-fpermissive]
/usr/include/string.h:143:12: error: initializing argument 2 of ‘int strcmp(const char*, const char*)’ [-fpermissive]
CTest.cpp: In function ‘int main()’:
CTest.cpp:16:12: error: invalid conversion from ‘const char*’ to ‘char’ [-fpermissive]
CTest.cpp:4:6: error: initializing argument 1 of ‘char max(char, char)’ [-fpermissive]
CTest.cpp:16:12: error: invalid conversion from ‘const char*’ to ‘char’ [-fpermissive]
CTest.cpp:4:6: error: initializing argument 2 of ‘char max(char, char)’ [-fpermissive]
1 #include <stdio.h>
2 #include <string.h>
3 
4 char max(char x, char y){
5 	
6 	if(strcmp(x,y)>0)
7 		return x;
8 	else
9 		return y;
10 	// else return '0';
11 }
12 
13 
14 main() {
15 
16 max("a","b");
17 
18 }

ar...@panix.com

unread,
Dec 16, 2012, 11:31:39 PM12/16/12
to Manor Perets, CPP forum, Ivan Chaplikov
Ummm.... That's nice but which class are you looking forward to?
Classes are over! Our next meeting is the final exam.
-- David A.

Manor Perets

unread,
Dec 16, 2012, 11:34:42 PM12/16/12
to bc...@googlegroups.com
Oh! Didn't realize that. Thanks for the pointer.
Best wishes,
Manor
Reply all
Reply to author
Forward
0 new messages