|
ODBC is more standarized and it would permit to change your database platform with only changing the connection string.
Marc Soleda.
|
|
|
|
|
hiho@ll
i need to convert a simple javascript i've found which generates a checksum to C
because i want to use it in a c prog
btw. i want to use this exact checksum code, so trieing another checksum algorithm isn't an option
here is only one line of code where i think the problem occures
i'll post the whole code as a reply so you can test it if you want
javascript:
<br />
c[r(i,3)]=(c[r(i,3)]-c[r(i+1,3)]-j)^(r(i,3)==1?j<<s[i]:j>>>s[i]);<br />
C:
<br />
c[r(i,3.0)]=(c[r(i,3.0)]-c[r(i+1,3.0)]-j)^(r(i,3.0)==1?j<<s[i]:j>>s[i]);<br />
r is defined as this:
<br />
#define r(x,y) (long long int)(floor(((x)/(y)-floor((x)/(y)))*(y)+0.1))<br />
and for testing you can use c as the following array:
<br />
long long int c[]={0x9E3779B9,0x9E3779B9,0xE6359A60};<br />
the problem is that i get wrong values within the C code
but the javascript code works
another problem was Visual Studio!!
i got complete different values for the whole code using visual studio
using the same code on Linux (i used cygwin) got me right values (for some part of the whole code)
don't know what the problem is/was but neither Visual Studio nor Linux got the one line described above work
i get wrong values
anybody knows the right conversion of the javascript code to C code?
thx@ll
|
|
|
|
|
the javascript:
<br />
<html><br />
<head><title></title><br />
<script type="text/javascript"><br />
<br />
function r(x,y){<br />
return Math.floor((x/y-Math.floor(x/y))*y+.1);<br />
}<br />
<br />
function m(c){<br />
var i,j,s=[13,8,13,12,16,5,3,10,15];<br />
for(i=0;i<9;i+=1){<br />
j=c[r(i+2,3)];<br />
c[r(i,3)]=(c[r(i,3)]-c[r(i+1,3)]-j)^(r(i,3)==1?j<<s[i]:j>>>s[i]);<br />
}<br />
}<br />
<br />
function getURL(url){<br />
url='info:'+url;<br />
var c=[0x9E3779B9,0x9E3779B9,0xE6359A60],i,j,k=0,l;<br />
for(l=url.length;l>=12;l-=12){<br />
for(i=0;i<16;i++){<br />
j=k+i;<br />
c[Math.floor(i/4)]+=url.charCodeAt(j)<<(r(j,4)*8);<br />
}<br />
m(c);<br />
k+=12;<br />
}<br />
c[2]+=url.length;<br />
for(i=l;i>0;i--)<br />
c[Math.floor((i-1)/4)]+=url.charCodeAt(k+i-1)<<(r(i-1,4)+(i>8?1:0))*8;<br />
m(c);<br />
return'6'+c[2];<br />
}<br />
<br />
</script><br />
</head><br />
<body><br />
<table><br />
<tr><br />
<td><br />
String:<br />
</td><br />
<td><br />
<input type="text" name="hmm"></input><br />
</td><br />
</tr><br />
<tr><br />
<td><br />
Checksum<br />
</td><br />
<td><br />
<input type="text" name="checksum" ></input><br />
</td><br />
</tr><br />
<table><br />
<input type="button" onClick="javascript:checksum.value=getURL(hmm.value);" value="Generate Checksum"><br />
</body><br />
</html><br />
the C code i already have:
<br />
#include <math.h><br />
#include <string.h><br />
#include <limits.h><br />
#include <stdio.h><br />
<br />
#define r(x,y) (long long int)(floor(((x)/(y)-floor((x)/(y)))*(y)+0.1))<br />
<br />
void m(long long int *c);<br />
void getUrl(char *tmp);<br />
void printc(long long int *c);<br />
<br />
void printc(long long int *c){<br />
for(long long int i=0;i<3;i++)<br />
printf("%lld ",c[i]);<br />
printf("\n");<br />
}<br />
<br />
int main(int argc, char **argv)<br />
{<br />
getUrl("http://fabmail.de/"); <br />
fgetc(stdin);<br />
return 0;<br />
}<br />
<br />
void m(long long int *c){<br />
long long int i,j,s[]={13,8,13,12,16,5,3,10,15};<br />
printc(c);<br />
for(i=0;i<9;i++){<br />
j=c[r(i+2,3.0)];<br />
c[r(i,3.0)]=(c[r(i,3.0)]-c[r(i+1,3.0)]-j)^(r(i,3.0)==1?j<<s[i]:j>>s[i]);<br />
}<br />
}<br />
<br />
void getUrl(char *tmp){<br />
char url[2048]={0};<br />
char ergebnis[1024]={0};<br />
if(tmp==NULL || strlen(tmp)>2084-6){<br />
return;<br />
}<br />
sprintf(url,"info:%s",tmp);<br />
long long int c[]={0x9E3779B9,0x9E3779B9,0xE6359A60};<br />
long long int i,j,k=0,l;<br />
for(l=(long long int)strlen(url);l>=12;l-=12){<br />
for(i=0;i<16;i++){<br />
j=k+i;<br />
c[(int)floor(i/4.0)]+=url[j]<<(r(j,4.0)*8);<br />
}<br />
m(c);<br />
k+=12;<br />
}<br />
c[2]+=(long long int)strlen(url);<br />
for(i=l;i>0;i--)<br />
c[(int)floor((i-1)/4.0)]+=url[(k+i-1)]<<(r(i-1,4.0)+(i>8?1:0))*8;<br />
m(c);<br />
sprintf(ergebnis,"6%lld",c[2]);<br />
printf("%s\n",ergebnis);<br />
}<br />
int the C code the problem is in the m(c); function
but i don't know what's wrong
-- modified at 9:10 Sunday 2nd October, 2005
|
|
|
|
|
Hello,
I am new in VS.Net and i have some knowledge about C#.Net. Now i want to learn VC++.Net by self study, so if any one tell me some free resource and startkit or any web which give trainning from start.
Thanks and regards,
|Muhamad Waqas Butt|
waqasb4all@yahoo.com
www.sktech.freewebspace.com
|
|
|
|
|
Hi
I thinck it is not the time to start VC++,It seem Microsoft does not need (&want) C++ programmers any more, I tring to forget VC++ ,but I ...
shame on Microsoft.
Iman Ghasrfakhri
|
|
|
|
|
Tnis is totally wrong.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
What microsoft did in 4-5 yearfor VC.NET ?
Managed Codes ,CLI or .... !?!?!
I don't know what microsoft wana to do about VC++ programmers
Iman Ghasrfakhri
|
|
|
|
|
Ghasrfakhri wrote:
What microsoft did in 4-5 yearfor VC.NET ?
Managed Codes ,CLI or .... !?!?!
and why do you think MFC is still supported ?
what you say is totaly wrong, and even if Microsoft wouldn't need C++ programmer, some entreprises do !
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
1. Standards conformance
2. new MFC
3. What do you think C# and VB.NET are written in ?
4. New Managed C++, if you want it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Ghasrfakhri wrote:
It seem Microsoft does not need (&want) C++ programmers any more...
Is this just your opinion, or do you have some factual data to back this claim up with?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
No direct factual data, But answer this Question what microsoft do for C++ programmers in .Net?
Iman Ghasrfakhri
|
|
|
|
|
Let me say my opinion and ask for more information from the experts here in CP:
VC++ will not die, because there is not any better language (yet) even in .net to do quick jobs with large amount of calculations. (And I don't think producer (probably a company) of a very expensive hardware decides to write drivers and app's with C#! while C# is sometimes 10 times slower, in some very special occasions, it's not good for this type of programming. (it even does not support Double!!!!))
But what about cross platform applications? What about commercial applications? I think they'll select a technology with which get to an application more quickly! Quality and Performance are not the first issue. In this case VC++ might be really obsolete!
Take a look at WinFX in Microsoft, please. What do you see? System.web, System.windows, System.Windows.Forms, System.Net, System.security (PF=Avalon, CF=indigo); Vista is going to offer a lot of new things to developers of .net. And Which one has the real focus in .net? Managed C++ (even without a visual editor!), C++/CLI, MFC, VB .net or just C #??!!
I believe C#.
Thinking a bit more. Next generation of programs. Parallel programming. Will that be easier to do this on machines which are OS independent (I've heared that .net platform and it's CLR is moving towards Linux, Mac OSX, so and so.) or doing it with VC++? So Microsoft might continue support of .Net, but frankly, I didn't see any thing good for C++ programmers at least before VS .net 2005, which I didn't see that yet!, in .net. For a C++ programmer ,however C++/CLI I think is the best choice, but I don't see any support in MFC for .Net, some one here said there is could you describe it more please, I'm really interested. (I lost my ClassWizard because C# don't like it and I have to write in the same IDE!
I love C++ and I hope MFC will be updated to use .Net easier and turns C++ to the first language of .Net, but it's much like a mirage.
I'm from the other side of the world and my knowledge certainly is incomplete and full of gaps. It will be appreciated to hear from those who have more information and science. To correct me and give some of the light of their knowledge to brighten the life!
P.S. English is not my native language, so please don't blame me on that!
|
|
|
|
|
I don't know of any resource beyond this site. If you know C# syntax, I'd be inclined to download some code from code project, and just play with it. If you're looking for a beginner book, 'teach yourself C++ in 24 hours' is pretty good.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
First of all, welcome to the most interesting part of your life! (Programming with C++);)
I believe much of it depends to yourself and the book or any other thing which will interest you. You may need to read more than one book!
I started with the fifth version of this book almost 2 years ago:
O'Reilly - Programming with Microsoft Visual C++ .NET I now about the sixth edition but perhaps there is a newer version available. (After CLI there must be)
You might search Amazon for that.
|
|
|
|
|
Imagine such a situation: you have a template data structure class, and you want to stream data from a file into your data structure. Values in the file should all be of the same primitive type, but the type itself is not recorded anywhere explicitly. And the question is: in the main program, how would you find out the type of values that a specific file stores? Because the type is needed to instantiate the data structure before you can start streaming data in...
If you guys want to understand the whole problem the link for the Project can be found at: http://www.cs.up.ac.za/download.php/COS212/Assignments/project1.pdf
or
http://www.cs.up.ac.za/download.php/COS212/Assignments/project1.ps
I've been struggling to find a sollution to this problem for weeks now. The project has to be in tomorrow.
Help would GREATLY be appreciated.
Thanks alot
|
|
|
|
|
As I understand, you have to use a template to create your tree, but you will manually select which type according to the input file.
for example, you will read int if the file contain int , double if te file contain double , ...
YourTreeStructure <int > yourIntTree;<br />
YourTreeStructure< double > yourDoubleTree;<br />
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
here's a sample line of codes
#1
CString strLine;
strLine = "Hello";
cout << strLine << endl;
output
007706BC
#2
CString strLine;
strLine = "Hello";
printf("%s\n", strLine);
output
Hello
Why didn't cout display the "Hello" string, but using printf will display the desired output. What's the difference between cout and printf that made the above discrepancy? Thanx
|
|
|
|
|
Try using String of char* instead of CString. Just remember to import <string> in your C++ file.
|
|
|
|
|
CString has the address of the memory location I think.
|
|
|
|
|
|
Use GetBuffer to the underlying char *, don't forget to call ReleaseBuffer after.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
benjnp wrote:
cout << strLine << endl;
use cout << (LPCTSTR)strLine << endl; instead...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Thanx guys, Now I know what's the difference and what to do. But since it is a console app, i'll use printf instead.
|
|
|
|
|
benjnp wrote:
since it is a console app, i'll use printf
otherwise?u'll use cout?
V
|
|
|
|
|
benjnp wrote:
But since it is a console app, i'll use printf instead.
This makes no sense at all. Both printf() and cout can be used for console applications.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|