|
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int tobase=0;
int number =0;
int counter = 0;
int bin [25];
int quo = 1;
printf("Enter your number:");
scanf("%d",&number);
printf("Enter base to convert to: ");
scanf("%d",&tobase);
while (quo!= 0)
{
quo= number/tobase;
bin[counter] = number%tobase;
counter ++;
number=quo;
}
while (counter > 0)
{
printf( "%d", bin[counter-1]);
counter --;
}
system("PAUSE");
return 0;
}
how to make this code into a function?
|
|
|
|
|
i have tried to come up with my own way of having a code but its not working ...corect it please .
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* Function Prototypes */
int bintodec(int fmbase, int num);
int dectobin(int tobase, int num);
int main()
{
int num;
int fmbase;
int tobase;
int result;
int convert;
int counter = 0;
int bin [25];
int quo = 1;
printf("Enter 0 to convert to binary\n");
printf("Enter 1 to convert to decimal\n");
scanf("%d",&convert);
printf("Enter the value to be converted:");
scanf("%d",&num);
printf("Enter base to be converted from: ");
scanf("%d",&fmbase);
printf("Enter base to be converted to: ");
scanf("%d",&tobase);
if(convert ==0)
convert= dectobin();
else if (convert ==1)
convert= bintodec();
else
{
printf("Error in Input");
exit(1);
}
result = bintodec(fmbase,num);
printf("The result is:%d", result);
result = dectobin(tobase,num);
printf("The result is:%d", result);
int dectobin( int tobase, int num)
do (quo!= 0)
{
quo= num/tobase;
bin[counter] = num%tobase;
counter ++;
num=quo;
}
while (counter > 0)
{
printf( "%d", bin[counter-1]);
counter --;
}
int bintodec(int fmbase, int num)
{
int bin[256];
int counter ;
int counterR ;
int quo ;
int result =0;
int result1 =0;
int res[256];
int sum =0;
if(quo>0)
{
quo= num/10;
bin[counter] = num%10;
num=quo;
counter++;
}
while (counter>0)
{
result = pow(fmbase, (counter-1));
result1=result*bin[counter-1];
res[counterR]=result1;
counter--;
counterR++;
}
while (counterR > 0)
{
sum = sum + res[counterR-1];
counterR--;
}
return sum;
}
system("PAUSE");
return 0;
|
|
|
|
|
NickYan wrote: corect it please
ok
Correct it please.
|
|
|
|
|
NickYan wrote: how to make this code into a function?
Other than the function it already is in? Apply some logic here, Nick.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
i know that i can do it but i need to write up a report with a set of headings in the assignment not only to get the code working and time is short 1 more day till its due
|
|
|
|
|
NickYan wrote: ...time is short 1 more day till its due
Good luck.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
thanks but you guys are suppose to help even if it is a little at least not only give advice .........
|
|
|
|
|
NickYan wrote: you guys are suppose to help
Helping you and doing it for you are two different things.
Why can you put together two functions, but not a third? That makes no sense, unless you've been sleeping in class.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
In dialog box if we have tab control we can have many pages. How to exchange message from one page to another?
|
|
|
|
|
The values should belong to the dialog and passed to each page. in each page you update the values in the dialog.
|
|
|
|
|
Thank you for your reply.
Could you explain more clear?
Supposed in page1 user input a number x=5, how to transfer it to page2?
|
|
|
|
|
|
|
Thank you very much, PJ Arends and Maximmilien.
I'll study it. Thanks.
|
|
|
|
|
How to attach source code?
My question can't say clear without source code.
|
|
|
|
|
I still have some questions.
|
|
|
|
|
Use the tags under the input text field hen you are posting.
this is "code" tag, used to highlight something
this is "pre", used to limite code snippets
you have less problems with lines length
and so on.
But please try to put code snippets, not whole sections of your programm
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
One possibility is to use the document. I think the MFC Document/View architecture is desiged such that you can use the document as a common place to hold the data. There might be times when the document needs to get data from the view, such as when the data is being saved, and that is possible but a little more complicated than you might hope. What you can do is that very time the page is changed, the old page could update the document and the new page can refresh the data from the document. I hope you understand.
|
|
|
|
|
Hi!
I've a working VB6 code whose purpose is to set a file handle to Windows clipboard,
just as the system does when you select a file in Explorer and give the "Copy" command.
My function, SetClipboardFiles wants a string() [VB6] or vector<string> [C++] as input
argument, containing a list of valid Fully Qualified Paths.
VB6 code works correctly, which means that if you set in clipboard an existing
file and then you perform a "paste" operation in the windows Explorer the
file is correctly copied.
I've migrated it to C++, but it really doesn't work. Why??
Can anyone help me??
I attach the code, without specifying all dependencies.
If someone wants to get more involved in the subject, I will.
Tnx
Mike
==============================================================================================
VB6 Original working CODE
==============================================================================================
Public Function SetClipboardFiles(file_names() As String) As Boolean
'from http://www.vb-helper.com/howto_get_set_clipboard_files.html
Dim file_string As String
Dim drop_files As DROPFILES
Dim memory_handle As Long
Dim memory_pointer As Long
Dim i As Long
' Clear the clipboard.
Clipboard.Clear
' Open the clipboard.
If OpenClipboard(0) Then
' Build a null-terminated list of file names.
For i = LBound(file_names) To UBound(file_names)
file_string = file_string & file_names(i) & _
vbNullChar
Next
file_string = file_string & vbNullChar
' Initialize the DROPFILES structure.
drop_files.pFiles = Len(drop_files)
drop_files.fWide = 0 ' ANSI characters.
drop_files.fNC = 0 ' Client coordinates.
' Get global memory to hold the DROPFILES
' structure and the file list string.
memory_handle = GlobalAlloc(GHND, Len(drop_files) + _
Len(file_string))
If memory_handle Then
' Lock the memory while we initialize it.
memory_pointer = GlobalLock(memory_handle)
' Copy the DROPFILES structure and the
' file string into the global memory.
CopyMem ByVal memory_pointer, drop_files, _
Len(drop_files)
CopyMem ByVal memory_pointer + Len(drop_files), _
ByVal file_string, Len(file_string)
GlobalUnlock memory_handle
' Copy the data to the clipboard.
SetClipboardData CF_HDROP, memory_handle
ClipboardSetFiles = True
End If
' Close the clipboard.
CloseClipboard
End If
End Function
==============================================================================================
C++ Migrated Code (NOT WORKING)
==============================================================================================
int cCLIPBOARD::SetClipboardFiles(vector<string> svFQPath)
{
/*
Creates CF_HDROP objects according to elements
of svFQPath
This Function IS NOT OPERATIVE. Ci manca davvero poco, vacca!
*/
string file_string; //buffer to be passed to win-clip
int file_string_sz;
vector<string>::iterator iter;
DROPFILES drop_files;
int drop_files_sz;
HGLOBAL memory_handle;
LPVOID memory_pointer;
DROPFILES* pMem;
DROPFILES* pMem2;
void *memory_pointer_2;
int _return;
if (OpenClipboard(0) !=0)
{
// Pulizia clipboard
if (EmptyClipboard()== false){cout << "CRITICAL ERROR: EmptyClipboard call failed";}
// Builds a null-terminated list of filenames
for (iter = svFQPath.begin(); iter < svFQPath.end(); iter++)
{file_string = file_string + *iter + '\0' ;}
file_string = file_string + '\0';
file_string_sz = file_string.size(); //13
// Initilalises DROPFILES struct
drop_files_sz = sizeof(drop_files); //20
drop_files.pFiles = drop_files_sz;
drop_files.fWide = 0; //ANSI CHARACTERS
drop_files.fNC = 0; //Client Coordinates
drop_files.pt.x =0 ;
drop_files.pt.y=0;
debug << "\n drop_files_sz = " << drop_files_sz;
// Get global memory to hold the DROPFILES structure and the file list string
memory_handle = GlobalAlloc(GHND,
drop_files_sz + file_string_sz);
if (memory_handle !=0)
{
// Lock the memory while we initialize it.
memory_pointer = LPVOID(GlobalLock(memory_handle));
// Copy 'drop_files' and "file_string'
//into the global memory
memcpy(memory_pointer,
&drop_files,
sizeof(drop_files));
memory_pointer_2 =reinterpret_cast<void*>(int(memory_pointer)
+ drop_files_sz) ; //drop_files_sz;
memcpy(memory_pointer_2,
file_string.c_str(),
file_string_sz);
pstr = (char*) memory_pointer_2;
// Releasing memory
GlobalUnlock(memory_handle);
// Copying the data from memory_handle to win-clip
if (SetClipboardData(CF_HDROP, HANDLE(memory_handle))!= 0)
_return = 1;
}
else
{_return = 0;}
CloseClipboard();
}
return 1;
}
|
|
|
|
|
So where's the problem? Please do not paste a whole wad of code and expect us to wade through it. Narrow it down to a few statements and we'll focus on those.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Actually, I don't know where the problem is!
I simply translated the VB6 code in C++, but it doesn't work (though no error is given).
An alternative solution would be: does anyone know how to set a CF_HDROP data type
to WINDOWS CLIPBOARD? I found lot of examples with text and images, but not with
file handles...
I put code chunks cause they should give exactly the same result, but they don't.
The idea was comparing them...
|
|
|
|
|
If your VB code works ok, but your C code doesn't work (although no compiling errors), why don't you try to execute both codes debugging step by step and compare intern variables, returns and so on. That way you should be able to isolate where the problem exactly is, and with this section, then come back to forum. Im sure that you will have a perfect answer to help you from anyone of the good programmers that are here.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
What exactly is _return being used for?
|
|
|
|
|
I SOLVED THE PROBLEM!
MSDN says EmptyClipboard() call provides the Win Clipboard
being released from avery thread previously attached to
it. Therefore, the OpenClipboard(NULL) call I perform
is vanified by subsequent EmptyClipboard(), and
I need one more OpenClipboard call.
THE STRANGE THING IS THAT THIS IS PERFECTLY TRUE IN C++,
BUT NOT IN VB6, FROM WHICH I WAS MIGRATING THE CODE!!!
mAH?
|
|
|
|
|
hello!
I`m not a choleric person, but this time i`m 2 steps away from madness!
I need to copy a file from one folder to another, so I`ve learned that i have to use
File.Copy, which is found in mscorlib.dll
I cannot find mscorlib.dll. Moreover, I don`t know how to link a lib to my project, so I usually simply "add existing item..." to my solution, and things just work. Only that this time it seems I can`t find the right mscorlib.dll
I have installed Visual Studio 2005, SP1, SDK for SmartDevices (WIN CE 5.0 and 6.0) - needed for some applications.
Visual Studio is installed in D:\Program Files\
I`ve seen that I have to download .NET Framework 2.0 (or 3.0), and I have downloaded them both from microsoft`s site.
Now, by searching my computer, i find 3 results of mscorlib.dll, in:
D:\Program Files\Microsoft Visual Studio 8\SmartDevices\SDK\CompactFramework\2.0\v1.0\WindowsCE
C:\Program Files\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE
C:\Program Files\Microsoft.NET\SDK\CompactFramework\v2.0\Debugger\BCL
(.Net installs itself without configuring the path)
(Where the hell is v3.0 ?!)
Long story short, how can I get to use File.Copy ?
I have seen that I must write:
<br />
#using <mscorlib.dll><br />
using namespace System;<br />
using namespace System::IO;<br />
By simply writing those lines, without any adding of that lib to my project (or adding any of those 3) I get errors on "identifiers not found".
I `ve seen that mscorlib.dll appears in many System related functions, so I hope someone will know how to make it work...
While waiting for this answer, I`m using fopen to continue working with the data, but I can`t finish my application without create folder and file.copy.
Many thanks for any suggestion!
Shpid3r
|
|
|
|