Reputation: 37
I just switch from vc6++ to vs2013, and find out that there are a lot of differences between them. Like using scanf_s instead of scanf, cmath instead of math.h getch -> _getch
Is there any other main difference that I should be aware of?
And by the way, what does this mean ? "error C2668: 'pow' : ambiguous call to overloaded"
Here is my codes, it is a simple encryption program
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<math.h>
int encode1(int d,int n);
int encode2(int d,int n);
int encode3(int d,int n);
int decode1(int d,int n);
int decode2(int d,int n);
int decode3(int d,int n);
int main(void)
{
char ans, exit;//Used to exit the program
puts("Program starts");
int d = 0, n, temp;
char s;
unsigned number;
printf("Please choose one of the followings \n");
printf("1)Encrypting\t2)Decrypting(q to quit)\n");
scanf("%d",&number);
while (number!= 1 && number != 'q'&& number != 2)
{
printf("Wrong choice, retry\n");
number = getchar();
}
if(number!='q')
{
printf("Please type in the digit of your password\n");
scanf("%d", &n);
getchar();
}
switch (number)
{
case 1: temp = encode1(d, n);
printf("%d\n", temp);
break;
case 2: temp = decode1(d, n);
printf("%d\n", temp);
break;
default:break;
}
puts("Press any key to continue");
exit = _getch();
puts("Program ends");
return 0;
}
int encode1(int d, int n)
{
int b, c[100], i, j, t, r, e[100];
puts("Please type in your password to generated the key(integers only)");
scanf("%d", &b);
for (i = 0; i<n+1; i++)
{
c[i] = b % 8;
b = b / 8;
}
for (i = 0; i<n+1; i++)
{
d = d * 10 + c[i];
}
r = encode2(d,n);
return r;
}
int encode2(int b, int n)
{
int c[100], i, j, t, r, d = 0;
for (i = 0; i<n+2; i++)
{
c[i] = b % 8;
b = b / 8;
}
for (i = 0; i<n+2; i++)
{
d = d * 10 + c[i];
}
r = encode3(d,n);
return r;
}
int encode3(int b, int n)
{
int c[100], i, j, t, r, d = 0;
for (i = 0; i<n+3; i++)
{
c[i] = b % 8;
b = b / 8;
}
for (i = 0; i<n+3; i++)
{
d = d * 10 + c[i];
}
return d;
}
int decode1(int d, int n)
{
puts("Type in the key to retrieve your password");
scanf("%d", &d);
int a[100], t, x;
int c[100], i, j, e[100], k, g, u = 0, r;
for (i = 0, j = n+3; i<n+3, j>0; j--, i++)
{
k = pow(10, j);
e[i] = d / (k);
}
for (i = 0, j = n+2; j >= 0, i<n+3; i++, j--)
{
g = pow(10, j + 1);
k = pow(10, j);
c[i] = (d - e[i] * g) / k;
}
for (i = 0, j = n+2; i<n+3, j >= 0; i++, j--)
{
t = c[j];
a[i] = t;
}
for (i = 0, j = n+2; i<n+3, j >= 0; i++, j--)
{
r = pow(8, j);
u += a[i] * r;
}
x = decode2(u,n);
return x;
}
int decode2(int d, int n)
{
int a[100], t;
int c[100], i, j, e[100], k, g, u = 0, r, x;
for (i = 0, j = n+2; i<n+2, j>0; j--, i++)
{
k = pow(10, j);
e[i] = d / (k);
}
for (i = 0, j = n+1; j >= 0, i<n+2; i++, j--)
{
g = pow(10, j + 1);
k = pow(10, j);
c[i] = (d - e[i] * g) / k;
}
for (i = 0, j = n+1; i<n+2, j >= 0; i++, j--)
{
t = c[j];
a[i] = t;
}
for (i = 0, j = n+1; i<n+2, j >= 0; i++, j--)
{
r = pow(8, j);
u += a[i] * r;
}
x = decode3(u,n);
return x;
}
int decode3(int d, int n)
{
int a[100], t;
int c[100], i, j, e[100], k, g, u = 0, r, x;
for (i = 0, j = n+1; i<n+1, j>0; j--, i++)
{
k = pow(10, j);
e[i] = d / (k);
}
for (i = 0, j = n; j >= 0, i<n+1; i++, j--)
{
g = pow(10, j + 1);
k = pow(10, j);
c[i] = (d - e[i] * g) / k;
}
for (i = 0, j = n; i<n+1, j >= 0; i++, j--)
{
t = c[j];
a[i] = t;
}
for (i = 0, j = n; i<n+1, j >= 0; i++, j--)
{
r = pow(8, j);
u += a[i] * r;
}
return u;
}
Upvotes: 0
Views: 170
Reputation: 11
Compare the C11 standards to the version of Visual Studio you were running under, most likely C99.
Biggest changes brought by C99 are as follows:
◾Variable length arrays
◾Designated initializers
◾Type-generic math library
◾New datatypes: long long, _Complex, _Bool
◾restrict pointers
◾Intermingled declarations of variables
◾Inline functions
◾One-line comments that begin with //
Biggest changes in C11:
New set of safer standard functions that aim to replace the traditional unsafe functions. For the typical C programmer, the biggest change in C11 is its standardized multithreading support.
The new C11 header file declares functions for creating and managing threads, mutexes, condition variables, and the _Atomic type qualifier. Another new header file, , declares facilities for uninterruptible objects access. Finally, C11 introduces a new storage class specifier, _Thread_local (the C equivalent of C++11’s thread_local). A variable declared _Thread_local isn’t shared by multiple threads. Rather, every thread gets a unique copy thereof.
Information Pulled From: http://blog.smartbear.com/codereviewer/c11-a-new-c-standard-aiming-at-safer-programming/
Good Read if you have the time.
Upvotes: 0
Reputation: 1268
Why didn't you post the code that gives you that error? Just guessing, you have something in the code that looks like:
int a = 1;
int b = 2;
double result = pow(a, b);
The issue is that both of the arguments passed to pow
are int
s, but there is no overload of pow
in math.h
that would take two int
s.
The compiler is telling you that it is having troubles in the the overload since the best viable function is not unique in this case.
You can fix this by casting the first parameter to a suitable type, such as double
:
double result = pow((double)a, b);
More in general, since there are many many changes, it should be nice if you could reduce the scope of your question.. Are you also planning to convert legacy MFC code?
However, post your errors, I have recently upgraded a couple of old projects so I can probably help you.
Upvotes: 1