|
-
Oct 21st, 2001, 06:52 PM
#1
Thread Starter
Hyperactive Member
char to int
Code:
int convert()
{
char str[10];
int len;
int ret,i;
cout<<"Enter a binary value";
cin>> str;
len = strlen(str);
int val;
for(i=len;i>=0;i--){
val = atoi(str[i]);//error here
//ret = pow(val, i);
cout << val<<endl;
return 0;
}
}
i get the error : cannot convert parameter 1 from 'char' to 'const char *'
what do i have to do to correct it? thanks
Matt 
-
Oct 21st, 2001, 07:05 PM
#2
Member
How about just atoi('x')?
-
Oct 21st, 2001, 08:05 PM
#3
Hyperactive Member
Re: char to int
Originally posted by MPrestonf12
Code:
int convert()
{
char str[10];
int len;
int ret,i;
cout<<"Enter a binary value";
cin>> str;
len = strlen(str);
int val;
char str2[2];
for(i=len;i>=0;i--){
str2[0]=str[i];
str2[1]='\0';
val = atoi(str2);//error here
//ret = pow(val, i);
cout << val<<endl;
return 0;
}
}
How about that? the parameter to atoi must be a string which end with null('\0'). cannot be a single char by itself.
Better to use kedaman's method here.converting char type to int
-
Oct 23rd, 2001, 08:20 PM
#4
Lively Member
Originally posted by CornedBee
Also, I recommend replacing isbin by a macro in C and an inline function in C++.
Why?
Wouldnt a macro be more efficient? Less overhead? inline functions still have to get processed....
if(GetWindowLong(hwnd,GWL_ID)==IDC_MICROSOFT_APPLICATION)
{
SetWindowText(hwnd,"I suck.");
SendMessage(hwnd,WM_START_SUCKING,0,0);
SendMessage(hwnd,WM_CRASH,0,0);
}
-
Oct 24th, 2001, 08:00 AM
#5
No. if you optimize for speed (not code size), inlines will behave just like macros.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 24th, 2001, 08:55 AM
#6
CB is right. Think about what a macro does. The compiler expands the macro and puts the code in the position where the macro was already.
When you inline f() it takes the f() code and moves it to the position where the function is called. Expands all the code onto the line - just like a macro.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|