|
I guessed the problem would be with populating the buffer ...
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
MFC, STUDIO 2008, MDI-project
Christ has arisen!
There are 2 classes:
class CADO_MDIView : public CscrollView
class CAdodc_MDI : public Cdialog
В class CADO_MDIView имеем
CString m_s5(“YYYYYYYYYYY”);
MessageBox(m_s);
// ADO_MDIView.cpp : implementation of the CADO_MDIView class
#include "stdafx.h"
#include "ADO_MDI.h"
#include "ADO_MDIDoc.h"
#include "CntrItem.h"
#include "ADO_MDIView.h"
#include "Adodc_MDI.h"
// Adodc_MDI.cpp : implementation file
#include "stdafx.h"
#include "ADO_MDI.h"
//-1 #include "ADO_MDIView.h"
#include "Adodc_MDI.h"
//-3 #include "ADO_MDIView.h"
CADO_MDIView dlg_View; // adodc_mdi.cpp(211)
dlg_View.m_s5;
--------------------------------------
ado_mdiview.h(23) : error C2143: syntax error : missing ';' before '*'
ado_mdiview.h(23) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
ado_mdiview.h(23) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
ado_mdiview.h(23) : warning C4183: 'GetDocument': missing return type; assumed to be a member function returning 'int'
adodc_mdi.cpp(211) : error C2248: 'CADO_MDIView::CADO_MDIView' : cannot access protected member declared in class 'CADO_MDIView'
ado_mdi\ado_mdiview.h(18) : see declaration of 'CADO_MDIView::CADO_MDIView'
ado_mdi\ado_mdiview.h(15) : see declaration of 'CADO_MDIView'
--------------------------------------
// Attributes
public:
CADO_MDIDoc* GetDocument() const; // ado_mdiview.h(23)
--------------------------------------
class CADO_MDIView : public CScrollView
{
protected: // create from serialization only
CADO_MDIView(); // ado_mdi\ado_mdiview.h(18)
|
|
|
|
|
Well, you have errors in your ado_mdiview.h . What else?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi,
I have two applications running in parallel.I want to know the events generated in one application (because of
user's action on dialog controls)in the other application.
Those two applications are not communicating with each other directly.But the second application has the info of
dialog control ID's of the first application.
Is it possible to know the events generated in other application.?
Please tell me how can I do it.
Regards,
Sunil Kumar
|
|
|
|
|
sunilkumar.d wrote: Is it possible to know the events generated in other application.?
Well, yes - Spy++ can do it.
I suspect you need to create a global Windows hook that gets injected into the first application which can send information to the second one.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi Stuart,
Thanks for the reply.
Can I get any detailed info on how to do this?
Regards,
Sunil Kumar
|
|
|
|
|
Try this article[^] - CP has lots of useful articles that are just a search away - learn how to use the resources you have available to you - at your fingertips!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi guys,
I have a following problem. I'm trying to read a range of data information from the following .dat file specified below.
I'm using the ifStream to read in the data from the Info.dat file. I have created the Student class object S[4], then using it to set the data that I've read in using variables. It is also a need for while loop to be used in the program. However, the problem is that it does not work out well.
My intended output is as such:
output:
------------
Alan <br />
no of subjects taken: 4<br />
no of passes :3<br />
total credits : 17 and so on.
Really appreciate the help.
Info.dat
Alan English 4 F Maths 3 P Science 5 P Geo 5 P
Danny English 2 P Maths 3 P Science 4 P Geo 2 P
Jane English 1 F Maths 3 F Science 3 P Computing 8 P
Keith English 5 P Maths 3 P Science 5 P Literature 4 P
int main()<br />
{<br />
Student S[4];
<br />
<br />
int count, credits, totalCred;<br />
string stud, module;<br />
char pass;<br />
<br />
int Cols;<br />
int Rows; <br />
<br />
Cols = 0;<br />
Rows = 0;<br />
<br />
<br />
count = 0;<br />
totalCU = 0;<br />
<br />
ifstream inFile;<br />
<br />
inFile.open("Info.dat");<br />
<br />
if (inFile.fail()){<br />
cout<<"ERROR: File cannot be opened!"<<endl;<br />
getchar();<br />
exit(1);<br />
}<br />
<br />
<br />
if (inFile.good()){<br />
<br />
<br />
<br />
while (Rows < 4){<br />
<br />
inFile>>stud;<br />
<br />
<br />
S[Rows].setName(stud); <br />
<br />
<br />
while (Cols < 4){ <br />
inFile >>module>>credits>>pass;<br />
<br />
S[Rows].setCode(module, Cols);<br />
...<br />
<br />
if (pass == 'P'){<br />
count++;<br />
}<br />
<br />
totalCred = totalCred + credits;<br />
<br />
Cols++;<br />
}<br />
<br />
<br />
S[Rows].setCount(count);<br />
<br />
<br />
<br />
<br />
<br />
<br />
Rows++;<br />
<br />
<br />
}<br />
}<br />
<br />
inFile.close();
DA: http://www.pohcbsonic.deviantart.com/
Blog: http://www.pohcbsonicx.blogspot.com/
Homepage: http://www.pohcbsonic.tripod.com/
modified on Tuesday, April 21, 2009 12:42 AM
|
|
|
|
|
pohcb_sonic wrote: if (pf == 'P'){
What is pf ? Where is it assigned a value?
pohcb_sonic wrote: totalCU = 0;
Where is this declared?
pohcb_sonic wrote: S[Cols].setCode(module, Cols);
Shouldn't this be:
S[Rows].setCode(module, Cols); pohcb_sonic wrote: while (Cols < 4)
When does Cols ever get reset so that this while() loop can run again for the next student?
pohcb_sonic wrote: totalCred = totalCred + credits;
Does totalCred accumulate for all four students?
What does your code do if more students are added, or a student adds/drops a class? Hint: it won't work.
All that aside, is your intent to do this in C using a few C++ objects, or create your own C++ classes and use the STL?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
ok, let me re-edit the question. =) please refer to the above question again.
DA: http://www.pohcbsonic.deviantart.com/
Blog: http://www.pohcbsonicx.blogspot.com/
Homepage: http://www.pohcbsonic.tripod.com/
|
|
|
|
|
pohcb_sonic wrote: My intended output is as such:
But what is the actual output? Have you stepped through the code using the debugger?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
The output I got is:
Alan English 4 F Maths 3 P Science 5 P Geo 5 P <br />
Danny English 2 P
which I think, is not correct.
I did use the debugger to step through, and what I got was that the stud variable only captures "Alan" and not "Danny". "Danny" was being received among the inFile >>module>>credits>>pass; portion.
DA: http://www.pohcbsonic.deviantart.com/
Blog: http://www.pohcbsonicx.blogspot.com/
Homepage: http://www.pohcbsonic.tripod.com/
|
|
|
|
|
pohcb_sonic wrote: I did use the debugger to step through...
And what did you notice about Cols as soon as "Danny" was read into stud ? Go back and re-read the questions in my first post. They give big clues as to what is wrong.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
I was wondering if anyone can help me convert my Graph Code I have in Java to C++. I have going at it for a week or so now and am having trouble. Any help would be appreciated. I will post all parts of the code that is involved for this code.
Also, I will post the assignment I have and if it's easier to just ignore everything I have and do it all from scratch then I will post what is needed and said in the assignment.
import java.io.*;
public class VNode {
private VNode next;
private int vertex;
public VNode() {
next = null;
vertex = 0;
}
public VNode (int a, VNode n) {
a = 0;
next = n;
}
public VNode getNext() {
return next;
}
public int getVertex() {
return vertex;
}
public void setNext(VNode ND) {
next = ND;
}
public void setItem(int IT) {
vertex = IT;
}
}
public class Graph {
private int [] ppath;
private VNode [] Vertices;
private boolean [] visited;
private boolean setVisited = false;
private VNode a;
private VNode previous;
private VNode b;
private VNode c;
private VNode prev;
//Sets up a graph with n vertices 0,1,...,n-1
public Graph(int n) {
Vertices = new VNode[n];
for (int i = 0; i < Vertices.length; i++) {
Vertices[i] = null;
}
}
//Inserts edge(i,j). Check bounds.
public void insert(int i, int j) {
if(Vertices[j] == null) {
Vertices[j] = new VNode(i, null);
}
else if(i < Vertices[j].getVertex()) {
a = Vertices[j];
Vertices[j] = new VNode(i, a);
}
else {
a = Vertices[j];
previous = null;
while(a != null) {
if(i < a.getVertex()) {
previous.setNext(new VNode(i,a));
break;
}
previous = a;
a = a.getNext();
}
if(a == null) {
previous.setNext(new VNode(i, null));
}
}
if(Vertices[i] == null) {
Vertices[i] = new VNode(j, null);
}
else if (j < Vertices[i].getVertex()) {
b = Vertices[i];
Vertices[i] = new VNode(j, b);
}
else {
c = Vertices[i];
prev = null;
while(c != null) {
if(j < c.getVertex()) {
prev.setNext(new VNode(j, c));
break;
}
prev = c;
c = c.getNext();
}
if (c == null) {
prev.setNext(new VNode(j, null));
}
}
}
//Returns a string representing a graph using set notation.
public String toString() {
String v = "V = {";
String e = "E = {";
int vertCount = 0;
//Prints out the vertices
for (int i = 0; i < Vertices.length; i++) {
v += vertCount;
if (vertCount == Vertices.length-1) {
v += "}";
}
else {
v += ", ";
}
vertCount++;
}
System.out.println(v);
//Prints out the edges
/*int edgeCount = 0;
for (VNode n = Vertices[0]; n != null; n = n.getNext()) {
while (n.getNext() != null) {
if (edgeCount == Vertices.length-1) {
e += "}";
}
else {
e += ", ";
}
}
edgeCount++;
} */
return (v + e);
}
//Returns a string representing the graph as an adjacency list.
public String getAdjList() {
String x = "";
for (int i = 0; i < Vertices.length; i++) {
VNode adj = Vertices[i];
System.out.println(adj);
x = i + ": ";
while (adj != null) {
if (adj.getNext() == null) {
x += adj.getVertex() ;
}
else {
x += ", ";
}
adj = adj.getNext();
}
}
return x;
}
//Performs a recursive depth first search starting at k.
//Print nodes in dfs order. Use least numbered vertex scheme.
public void dfs(int k) {
if(!setVisited) {
visited = new boolean[Vertices.length];
for (int i = 0; i < visited.length; i++) {
visited[i] = false;
}
setVisited = true;
}
depthFirstSearch(k);
}
//From dfs. Actually does the searching and printing.
//The dfs just initialized the visited array.
public void depthFirstSearch(int k) {
System.out.println("K = ");
visited[k] = true;
for (VNode n = Vertices[k]; n != null; n = n.getNext()) {
if(!visited[n.getVertex()]) {
visited[n.getVertex()] = true;
System.out.print(n.getVertex());
depthFirstSearch(n.getVertex());
}
}
}
//Performs a breadth first search using a queue.
//Prints nodes in bfs order. Use least numbered vertex scheme.
public void bfs(int k) {
visited = new boolean[Vertices.length];
Queue q = new Queue();
for (int i = 0; i < Vertices.length; i++) {
visited[k] = true;
}
q.enqueue(k);
while(!q.isEmpty()) {
int w = (Integer)q.dequeue();
System.out.println("The value of w = " + w);
for (VNode n = Vertices[w]; n != null; n = n.getNext()) {
if (!visited[n.getVertex()]) {
visited[n.getVertex()] = true;
q.enqueue(n.getVertex());
}
}
}
}
//Returns the shortest path between r and s.
//If no such path exists, return null.
public int[] shortestPath(int r, int s) {
visited = new boolean[Vertices.length];
Queue q = new Queue();
ppath = new int[Vertices.length];
for (int i = 0; i < Vertices.length; i++) {
visited[r] = true;
}
//Initializes all entries in ppath to -2.
for (int a = 0; a < ppath.length; a++) {
ppath[a] = -2;
}
q.enqueue(r);
ppath[r] = -1;
while(!q.isEmpty()) {
int w = (Integer)q.dequeue();
System.out.println("The value of w = " + w);
for (VNode n = Vertices[w]; n != null; n = n.getNext()) {
if (!visited[n.getVertex()]) {
visited[n.getVertex()] = true;
ppath[n.getVertex()] = w;
q.enqueue(n.getVertex());
}
}
}
int y = 0;
int z = s;
return null;
}
}//end of Graph Class
So that is the java code.
Here is the assignment asked.
//struct Edge { int v1, int v2, int weight; }
//weight of -1 = no weight
void initGraph(int n, bool directed);
//may be a constructor - intialize a graph with n verticies
//the graph will be directed if directed is set to true
void addEdge(Edge edge)
//add an edge to the graph
int getAdjacentList(int v, List& adjList){
//puts in adjlist the vertices adjacent to v
//returns # vertices in adjlist
}
int getEdgeList(List& edgeList){
//puts in edgeList the list of edges in the graph
//for undirected graph, only 1 copy of the edge is needed
//returns # edges in edgeList
}
bool isPath(int start, int end, List& path){
//returns true if there is a path from start to end
//use Depth-First search algorithm (a private method)
//puts in path the list of vertices on the path from
// start to end (if there is a path)
}
Thanks for all and any help.
|
|
|
|
|
NxtGr8One wrote: I will post all parts of the code that is involved for this code.
[sarcastic]As opposed to just one piece at a time? Thanks.[/sarcastic]
NxtGr8One wrote: public class VNode {
private VNode next;
private int vertex;
public VNode() {
next = null;
vertex = 0;
}
Something like:
class VNode
{
private:
VNode *next;
int vertex;
public:
VNode()
{
next = NULL;
vertex = 0;
}
VNode( int a, VNode *n )
{
a = 0;
next = n;
}
VNode* getNext( void )
{
return next;
}
}; I trust you can attempt the rest.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Is it possible to have a C++ program work only if it is within a certain directory, say.. C:\Program Files\Random Folder ?
If so, any tips as to what code I would use?
|
|
|
|
|
Use _getcwd() or GetCurrentDirectory() and check the results.
PS. The comment below to use GetModuleFileName(NULL, ...) is the right answer. You can then compare the string using lstrcmpi(), the Win32 CompareString() function or something similar.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
modified on Tuesday, April 21, 2009 11:18 AM
|
|
|
|
|
#include <direct.h> // for getcwd
#include <stdlib.h>// for MAX_PATH
#include <windows.h>
#include <iostream> // for cout and cin
using namespace std;
// function to return the current working directory
// this is generally the application path
void GetCurrentPath(char* buffer)
{
getcwd(buffer, _MAX_PATH);
}
int main()
{
// _MAX_PATH is the maximum length allowed for a path
char CurrentPath[_MAX_PATH];
// use the function to get the path
GetCurrentPath(CurrentPath);
// display the path for demo purposes only
char temp[_MAX_PATH];
char temp1[_MAX_PATH]={"C:\\Program Files"};
if(CurrentPath==temp1){
cout << CurrentPath << endl;
cout << temp1 << endl;}
cout << "Press Enter to continue";
cin.getline(temp,_MAX_PATH);
return 0;
}
Thats what I have, and it outputs the current path and what temp1 holds when the if statement is gone, but no matter what I cannot get the program to check if its in the right directory. Any more tips?
|
|
|
|
|
gamefreak2291 wrote: if(CurrentPath==temp1){
You should be using some sort of string compare routine here (e.g., strcmp() ).
Have you used the debugger to step through the code?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Thanks again, opened up my book, went right to str functions found strcmp and here is the working code:
#include <direct.h>
#include <stdlib.h>
#include <windows.h>
#include <iostream>
using namespace std;
void GetCurrentPath(char* buffer)
{
getcwd(buffer, _MAX_PATH);
}
int main()
{
char CurrentPath[_MAX_PATH];
GetCurrentPath(CurrentPath);
char temp[_MAX_PATH];
char temp1[_MAX_PATH]={"C:\\Program Files\\uTorrent"};
if(strcmp(CurrentPath, temp1)==0){
cout << CurrentPath << endl;
cout << temp1 << endl;}
cout << "Press Enter to continue";
cin.getline(temp,_MAX_PATH);
return 0;
}</iostream></windows.h></stdlib.h></direct.h>
|
|
|
|
|
Use GetModuleFileName().
The other response is not going to work in all cases (GetCurrentDirectory) since your program could be run from a shortcut on the desktop, and that shortcut could specify a different working directory.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
I've been trying to read up on some options of what I might be able to use. Perhaps, it can be better explained if I tell you what I would like to do.
I was hoping for a bit oriented class that not only provided storage on a per bit basis but also had the capability to provide an actual value. If you have binary data say in the form of messages in various formats, some of the binary data may use a single bit or a group of bits. In other words, a single bit is really a bit flag or boolean true or false, while a group of bits is a value. Of course, the groups of bits and bit flags may actually be intermixed say in a 16-bit word.
I've got 16-bit words (comprised of bit flags and bit field groups). It would be kind of nice to group the bits into bit fields and flags, e.g. say a 16-bit field comprised of three 4-bit fields, a 2-bit field and two single bit flags. I would like to make the contents of these bit fields somewhat human readable by decoding the binary in the same left to right order as they are stored in binary. We typically do this by using structures. This works fine for decoding but I would like to do something different.
If I could wrap these bit fields and flags into groups within an array or individual objects, I then would have the capability to name or label each object, bit field or group, and perform comparisons on similar data. In other words what may be a 4-bit field in one message may be a 3-bit field in another type of message, by writing a conversion routine between the two types, I still can make a similar comparison and not an exact comparison.
I'd have to design my own class but if I inherit from one of the previously mentioned classes, which one do you think would be best? For now, I have fixed data sizes but may need more flexible and unknown (until runtime) data sizes in the future. I'm not sure if I would want to wrap all of the bitfields or groups of bits that comprise a single message into a single object that would have a message type as a data member but I think I would like to.
|
|
|
|
|
JohnnyG wrote: if I inherit from one of the previously mentioned classes, which one do you think would be best?
JohnnyG wrote: may need more flexible and unknown (until runtime) data sizes
I'd alter each of your fields to be a method (rather than a data member) and extract it using bit-field extraction.
For instance, say we have a field 'A':
class MyBitFields
{
public:
MyBitFields(uint16_t compositeValue) : value_(compositeValue)
{
}
void SetA(unsigned int offset, unsigned int size) { aOffset_ = offset; aSize_ = size; }
unsigned int getA() { return (value_>>aOffset_) & ((1<<aSize_)-1); }
private:
uint16_t value_;
uint8_t aOffset_;
uint8_t aSize_;
};
?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
That's an interesting idea and may be exactly what I need since I am not intending to store every binary data value read from a file into the MyBitFields class permanently but rather to help me decode and perhaps to compare. I also could have a data member inside of MyBitFields and even have conversion modifiers inside of the class.
Additionally, I could also create an array of MyBitFields, one array per message
Thanks for the info!
|
|
|
|
|
I've noticed that sprintf() does some interesting things with the numbers, for example:
double : 8.38750000 sprintf: 8.387
double : 9.23750000 sprintf: 9.238
The final sprintf() was achieved with code like this:
double d = 9.23750000;
sprintf( tmp, "%0.3f", d );
In the case of 8.3875, no rounding appears to taking place. In the case of 9.2375, we get rounding! Is this normal? Is there a way to prevent this?
Bah humbug, it helps to actually examine the damn number more closely. Never mind!
Thanks to everyone who answered below!
modified on Monday, April 20, 2009 4:41 PM
|
|
|
|