|
All of these questions can be answered by reading the language references here[^].
|
|
|
|
|
#include <stdio.h>
#include <stdlib.h>
void load(int*, int*, int*);
void display(int*, int*, int*);
void compute(int*, int*, int*);
void adder(int*, int*);
void negate(int*);
void main()
{
int i;
int DIVISOR [5];
int REMAINDER [5];
int DIV_QUOT [4];
load(DIVISOR, REMAINDER, DIV_QUOT);
printf(" DIVISOR |\t REMAINDER\t DIVIDEND/QUOTIENT");
printf("\n --------|----------------");
printf("---------------------------\n");
display(DIVISOR, REMAINDER, DIV_QUOT);
printf("\n --------|----------------");
printf("---------------------------\n");
for (i=0; i<4; i++)
{
compute(DIVISOR, REMAINDER, DIV_QUOT);
printf("\n --------|----------------");
printf("---------------------------\n");
}
}
void compute(int DIVISOR[], int REMAINDER[], int DIV_QUOT[])
{
int DIVISOR_Copy [5];
bool neg;
REMAINDER[1] = REMAINDER[2];
REMAINDER[2] = REMAINDER[3];
REMAINDER[3] = REMAINDER[4];
REMAINDER[4] = DIV_QUOT[0];
DIV_QUOT[0] = DIV_QUOT[1];
DIV_QUOT[1] = DIV_QUOT[2];
DIV_QUOT[2] = DIV_QUOT[3];
DIV_QUOT[3] = 888;
display(DIVISOR, REMAINDER, DIV_QUOT);
printf(" | <--- Shifting left...\n");
DIVISOR_Copy[0] = DIVISOR[0];
DIVISOR_Copy[1] = DIVISOR[1];
DIVISOR_Copy[2] = DIVISOR[2];
DIVISOR_Copy[3] = DIVISOR[3];
DIVISOR_Copy[4] = DIVISOR[4];
negate(DIVISOR_Copy);
adder(REMAINDER, DIVISOR_Copy);
if (REMAINDER[0] == 1)
neg = 1; else
neg = 0;
display(DIVISOR, REMAINDER, DIV_QUOT);
if (neg)
{
adder(REMAINDER, DIVISOR);
DIV_QUOT[3] = 0;
printf(" | NEGATIVE. ? = 0\n");
}
else
{
DIV_QUOT[3] = 1;
printf(" | POSITIVE. ? = 1\n");
}
display(DIVISOR, REMAINDER, DIV_QUOT);
}
void negate(int A[])
{
int i;
int ONE[5];
ONE[0] = 0;
ONE[1] = 0;
ONE[2] = 0;
ONE[3] = 0;
ONE[4] = 1;
for (i=0; i<=4; i++)
{
if(A[i] == 1)
A[i] = 0;
else
A[i] = 1;
}
adder(A, ONE);
}
void adder(int A[], int B[])
{
int next, i, carry=0;
for (i=4; i>=0; i--)
{
next = 1;
if (A[i]==0 && B[i]==0)
{
A[i]= carry;
carry = 0;
next = 0;
}
if (next)
if (A[i]==0 && B[i]==1)
{
if (carry == 0)
A[i] =1;
else
A[i]=0;
next = 0;
}
if(next)
if (A[i]==1 && B[i]==0)
{
if (carry == 0)
A[i] =1;
else
A[i]=0;
next = 0;
}
if(next)
if (A[i]==1 && B[i]==1)
{
if (carry == 0)
{
A[i] =0;
carry = 1;
}
else
A[i]=1;
next = 0;
}
}
}
void display(int A[], int B[], int C[])
{
int i;
printf(" ");
for(i=1; i<=4; i++)
printf(" %d", A[i]);
printf(" | ");
for(i=1; i<=4; i++)
printf(" %d", B[i]);
printf(" ");
for(i=0; i<=3; i++)
if ((C[i] == 0) || (C[i] == 1))
printf(" %d", C[i]);
else
printf(" ?");
}
void load(int A[], int B[], int C[])
{
A[0] = 0;
A[1] = 1;
A[2] = 0;
A[3] = 0;
A[4] = 0;
B[0] = 0;
B[1] = 0;
B[2] = 0;
B[3] = 0;
B[4] = 0;
C[0] = 1;
C[1] = 0;
C[2] = 0;
C[3] = 0;
}
|
|
|
|
|
Any body Can tell me logic gate function in binary value in C3
|
|
|
|
|
You wanna modify your title of this thread because your other thread has the EXACT same title, do it before the moderators or admin takes some hard action against you.
But anyways, a Google(R) search here may give the answer, I mean hey Google may suck from time to time, but why not give it a try? your be surprised what you may find, try looking on the other pages except the first page of results.
Simple Thanks and Regards,
Brandon T. H.
Programming in C and C++ now, now developing applications, services and drivers (and maybe some kernel modules...psst kernel-mode drivers...psst).
Many of life's failures are people who did not realize how close they were to success when they gave up. - Thomas Edison
|
|
|
|
|
plz any one can send me logic gates in C#
|
|
|
|
|
|
I need ftp C/C++ functions/classes to process ftp uploading/downloading tasks.
When I used software [FileZilla FTP Client], it sends/obtains many interesting events/messages, such as:
Status: Resolving address of www.xyz.com
Status: Connecting to 11.222.333.444:21...
Status: Connection established, waiting for welcome message...
Response: 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
Response: 220-You are user number 3 of 1000 allowed.
Response: 220-Local time is now 15:16. Server port: 21.
Response: 220-This is a private system - No anonymous login
Response: 220-IPv6 connections are also welcome on this server.
Response: 220 You will be disconnected after 15 minutes of inactivity.
Command: USER xyz
Response: 331 User xyz OK. Password required
Command: PASS *****************
Response: 230 OK. Current restricted directory is /
Command: SYST
Response: 215 UNIX Type: L8
Command: FEAT
Response: 211-Extensions supported:
Response: EPRT
Response: IDLE
Response: MDTM
Response: SIZE
Response: REST STREAM
Response: MLST type*;size*;sizd*;modify*;UNIX.mode*;UNIX.uid*;UNIX.gid*;unique*;
Response: MLSD
Response: AUTH TLS
Response: PBSZ
Response: PROT
Response: ESTA
Response: PASV
Response: EPSV
Response: SPSV
Response: ESTP
Response: 211 End.
Status: Connected
Status: Retrieving directory listing...
Command: PWD
Response: 257 "/" is your current location
Command: TYPE I
Response: 200 TYPE is now 8-bit binary
Command: PASV
Response: 227 Entering Passive Mode (74,220,215,241,4,101)
Command: MLSD
Response: 150 Accepted data connection
Response: 226-Options: -a -l
Response: 226 33 matches total
Status: Directory listing successful
(many more ...)
Those events are very useful and in details, I think MFC FTP classes are NOT powerful enough to process them.
What FTP C/C++ functions/classes are used by [FileZilla FTP Client] (or better than them)? I'd like to try them.
Thanks for links and comments.
.
|
|
|
|
|
|
I have created very simple dialog based project by using visual C++.
I have build it in release mode
Now I added this exe is FileGroups link of installshild ,then I compiled and run the setup
folder get created in C:\program files ,but it contains only uninst.isu file
I have licenced version of Visual studio 6.0,so problem of corrupt files.,
Please help me on this issue
Be Happy
|
|
|
|
|
What is the MFC mechanism for accessing UI controls from background threads?
In C#, we use "InvokeRequired " and "BeginInvoke " to schedule a function call on the UI thread, but how is that done in MFC?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
In MFC, you should not directly access UI elements from background threads.
Instead, you must send messages to the UI thread to get and set elements for the UI.
Use can use SendMessage or PostMessage .
modified 23-Jun-12 0:36am.
|
|
|
|
|
«_Superman_» wrote: In MFC, you should not directly access UI elements from background threads.
True.
«_Superman_» wrote: Instead, you must send messages to the UI thread to get and set elements for the UI.
Use can use SendMessage or PostMessage .
Not entirely true.
The reason for not accessing UI elements from another thread than the main thread is that you can quite easily create a deadlock situation. MFC classes for UI elements uses ::SendMessage() which will block until the message has been handled. If the main thread is not processing messages, possibly waiting for the thread that manipulates the UI element, the application will deadlock.
This of course means that you cannot use ::SendMessage() , even if you call it directly, as it would create the same potential deadlock situation.
::PostMessage() must be used since it doesn't wait for the message to be handled. It is possible to use ::SendMessageTimeout() to avoid a deadlock situation, but if the call fails the receiving thread never gets the message.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Thanks for clarifying that!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
SendMessage and PostMessage will do the job. You may also like to use PostThreadMessage instead of PostMessage
|
|
|
|
|
If you pass the window handle that contains the UI you want to manipulate to the thread when created you can use it in ::PostMessage().
|
|
|
|
|
Have a look at the below code:
#include "stdafx.h"
#include "conio.h"
int _tmain(int argc, _TCHAR* argv[])
{
char name[20] = "Some Name";
printf("%s\n", name);
name[1] = 'a';
printf("%s\n", name);
char * name2 = "Some Name";
printf("%s\n", name2);
name2[1] = 'a';
printf("%s\n", name2);
getch();
return 0;
}
Why we get Runtime error when we modify name2[1] = 'a';?
|
|
|
|
|
It all boils down to the difference between an array and a pointer. For name , you have set aside room for 20 characters (that are initialized to "Some Name"). For name2 , you are pointing to a static piece of memory. That memory cannot be changed.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Thanks Crow. That is constant piece of memory.
|
|
|
|
|
In this case... your definition of name2 is what is referred to as a string literal and points to data that is considered constant.
See here[^].
|
|
|
|
|
You are trying to modify a const char array (pointer).
This is not C++.
if you were writing proper C++, you would not get those problems (or a lot less likely).
std::string name = "some name";
std::cout << name << std::endl;
std::string name2 = "some name";
std::cout << name2 << std::endl;
name2[1] = 'a';
std::cout << name2 << std::endl;
Watched code never compiles.
|
|
|
|
|
Technically, to pick nits, it *is* C++ as C++ is a superset of C. What you are really saying is that it isn't "Object Oriented Programming" which is true, but it is still within the definition of C++.
|
|
|
|
|
Chuck O'Toole wrote: Technically, to pick nits, it *is* C++ as C++ is a superset of C
Does the newest ANSI C++ standard incorporate the latest ANSI C standard as a subset?
Last I heard that was not the case
|
|
|
|
|
The point is, C++ did *not* decommit the "char" data type nor pointers. std::string is *not* the only way to do string manipulation in C++. It may be the perferred way for some people but it's not the only way.
|
|
|
|
|
Chuck O'Toole wrote: The point is, C++ did *not* decommit the "char" data type nor pointer
I was responding to what appeared to be a general comment about the language in general and in its entirety and not just one small part.
And that general comment, at this time (new standards), is wrong.
|
|
|
|
|
Context dude, gotta read comments in the context of the thread
|
|
|
|