|
|
Thanks for the links. I should have search the articles section first.
<font=arial>Weiye Chen
Life is hard, yet we are made of flesh...
|
|
|
|
|
Very new to c++.
I need to extract specific data from a comma delimited file and then and created a new comma delimited file with the extracted data.
Help is appreciated
Thanks
Joe M
|
|
|
|
|
This makes no since (it would be simple to do your self), but someone at MS thought differently.
CopyFile() or CopyFileEx().
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
i want to apply ado to access database. i put following in my stdafx.h
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" no_namespace rename("EOF", "adoEOF")
but when i compile ,there are "error C2011: 'LockTypeEnum' : 'enum' type redefinition".
what should i change no_namespace into?
|
|
|
|
|
the bit at the end that says rename ("EOF", "adoEOF") could possibly also be used to rename LockTypeEnum ( I don't know for sure ). Or you could check where the clash is and fix it at the other end ( the other place that defines LockTypeEnum ). Or you can remove it entirely, which means that ADO will be imported within a namespace.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I have a linked list each node of it hase (name,phone....)
I want to sort it by name
struct PhoneBookEntry
{
CString Name,Email,Website,Adress;
CString OfPhone,HoPhone,Mobile;
};
typedef CList<phonebookentry *,="" phonebookentry="" *=""> PhoneBook;
PhoneBookEntry* InputEntry()
{
PhoneBookEntry* pEntry = new PhoneBookEntry;
cout << " Enter New Contact Details:" << endl;
cout << " Name : ";
char cName[100];
gets(cName);
return pEntry;
}
void main()
int nChoice
switch (nChoice)
{
case 1: // add contact
PhoneBookEntry *pEntry;
pEntry = InputEntry();
g_PhoneBook.AddTail(pEntry);
break;
case 2: // list entries
pos = g_PhoneBook.GetHeadPosition();
while (pos)
{
PhoneBookEntry* pEntry = g_PhoneBook.GetNext(pos);
PrintEntry(pEntry);
}
break;
|
|
|
|
|
|
how can I switch to std::list, and use std::sort. ??!
I didnt understand.....sorry
|
|
|
|
|
The list container is part of the STL.
Simple sort example:
<br />
#include "stdafx.h"<br />
<br />
#include <list><br />
#include <algorithm>
<br />
bool sortAscending(int a, int b)<br />
{<br />
return (a < b);<br />
}<br />
<br />
bool sortDescending(int a, int b)<br />
{<br />
return (b < a);<br />
}<br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
std::list<int> myList;<br />
<br />
myList.push_back(2);<br />
myList.push_back(1);<br />
myList.push_back(4);<br />
<br />
std::cout << "Before sort" << std::endl;<br />
for (std::list<int>::iterator i = myList.begin(), iEnd = myList.end();<br />
i != iEnd; ++i)<br />
{<br />
std::cout << (*i) << std::endl;<br />
}<br />
<br />
myList.sort(sortAscending);<br />
<br />
std::cout << "Ascending sort" << std::endl;<br />
for (std::list<int>::iterator i = myList.begin(), iEnd = myList.end();<br />
i != iEnd; ++i)<br />
{<br />
std::cout << (*i) << std::endl;<br />
}<br />
<br />
myList.sort(sortDescending);<br />
<br />
std::cout << "Descending sort" << std::endl;<br />
for (std::list<int>::iterator i = myList.begin(), iEnd = myList.end();<br />
i != iEnd; ++i)<br />
{<br />
std::cout << (*i) << std::endl;<br />
}<br />
<br />
return 0;<br />
}<br />
|
|
|
|
|
is this sort int or sting?
I need to soet strings
|
|
|
|
|
Read up on the Standard Template Library (STL).
The purpose of this library is the containers (such as lists) and be applied to any data type, it is universal.
Elaine
The tigress is here
|
|
|
|
|
How can I change the color of my comments in the IDE? Sometimes I make changes to my code and want to make them the code or maybe the comments red. I am using VStudio.net.
Jerry
|
|
|
|
|
|
I have 2 functions that need to communicate with the same device using the same COM Port. Problem is sometimes they do so at the sametime and end up reading the wrong data. Is there anyway that I can have both use the same comport without having this conflict?
I thought about Overlapped I/O, but I am not all to familiar with how to implement it and am not sure if it will solve my problem.
Thanks
|
|
|
|
|
Brute force method:
Add a comport_status flag and a pair of functions to set and check the status - BUSY or NOT_BUSY - then modify each I/O function to test the port status before attempting to use it. BUSY would be set by the function just prior to using the port, then on completion, it would reset the status to NOT_BUSY. There are certainly more elegant ways to do this, but it's one approach.
"...putting all your eggs in one basket along with your bowling ball and gym clothes only gets you scrambled eggs and an extra laundry day... " - Jeffry J. Brickley
|
|
|
|
|
Very strange, because only one function can communicate at a time; unless they are in seperate threads. If you have 2 different threads trying to communicate using the same comport, then you have a bad design. That does not mean you can not do it, what it means is you made a mistake in disign; it can be done but it does not make any since.
May be you explaned it wrong or you worded the question wrong. As you can see from my above answer there is something missing. If you can, write a minimum code example (tested) that shows the problem; the attempt to do so will probably show you the answer.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Each function is in a seperate thread. I am sorry I forgot to mention that.
function1 loops in its own thread until the program closes it. It reads from COM port 2 every second (1000 ms). I did this because this function/Thread needs to update the GUI/Edit box every second. so I left it seperate from everything else going on.
The other function, function2 is in another thread of its own reads from COM1 until all values it needs is read then it reads from COM2 as well to get data from there.
The problem arises because function2 will read from COM2 more then once per second (like every 200ms or so). So it occurs where at some point both functions read from COM2 at the sametime thus causing one or both functions to read the wrong incoming data.
I tried to do a "COMM in use" flag like Roger said above, but it didnt work because like I said at some point both will use the port at the sametime thus not allowing one function to set the flag in time before the other uses it.
|
|
|
|
|
You seem to have more problems than function2 (thread2) reading from the comport more than once per second.
1) function1 does not need to be in a thread, it only reads once per second. Therefore, it can can be done in a OnTimer-(WM_TIMER) method.
2) How does function2 know that function1 is finished reading (or vis-versa)? Normaly you would set an event, that says, I have finished reading may data; then function(?) can read any data that it may be expecting to receive.
What you are describing is a nightmare, that I (am surprised) have not seen before. I do not know why one thread would be getting its data from 2 different ports (one shared) (again this smacks of poor design [which I assume was not yours]). In ether case both threads needs to know when the other thread has finished reading its data from the given port; they have to set an event (signaling that they are finished).
I wish I could help more, but, like I said, this makes no since. Who ever designed the origanal (COM) system, created a very bad design.
Good Luck!
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Use a Mutex, commeon to both threads. Should solve the problem.
|
|
|
|
|
#include <iostream>
#include <fstream>
using namespace std;
double** input_mat(int x,int y);
double** expand_mat(double** g,double** f,int d,int e);
void swap(double &m,double &n);
double** mult_row(double** q,double x1,int i1,int j1);
double** substract_row(double** w,int i2,int i3,int j2):
double** swap_row(double** s,int i4,int i5,int j3);
int main()
{
double** a;
double** b;
double** c;
double h,r;
int row,col;
cout<<"Enter the number of rows then coloumns of the matrix \n";
cin>>row>>col;
a=input_mat(row,col);
b=new double*[row];
for(int k=0;k<row;k++){
b[k]=new double[(2*col)];
}
b=expand_mat(a,b,row,col);
for(int j=0;j<col;j++)
{
if(b[(row-1)][j]!=0){
b=mult_row(b,b[(row-1)][j],(row-1),col);
for(int k=0;k<(row-1);k++){
b=mult_row(b,b[k][j],(row-1),col);
b=substract_row(b,k,(row-1),col);
}
b=swap_row(b,j,(row-1),col);
}
}
c=new double*[row];
for(int k1=0;k1<row;k1++){
c[k1]=new double[col];
}
ofstream out("Inverse");
if(!out){
cout<<"Cannot open file \n";
return 1;
}
for(int u=0;u<row;u++){
for(int v=0;v<(2*col);v++){
out<<b[u][v]<<endl;
}
}
out<<b[(row-1)][0]<<b[0][0]<<b[0][1]<<b[1][1];
return 0;
}
double** input_mat(int x,int y)
{
double** matrix;
matrix=new double*[x];
for(int i=0;i<x;i++)
{
matrix[i]=new double[y];
for(int j=0;j<y;j++)
{
cout<<"enter the element"<<j+1<<"in the row"<<i+1<<":";
cin>>matrix[i][j];
}
}
return matrix;
}
double** expand_mat(double** g,double** f,int d,int e)
{
for(int i=0;i<d;i++)
{
for(int j=0;j<e;j++)
{
f[i][j]=g[i][j];
}
}
for(int u=0;u<d;u++)
{
for(int v=e;v<(2*e);v++){
if((u+e)==v){
f[u][v]=1;
}else{
f[u][v]=0;
}
}
}
return f;
}
void swap(double &m,double &n)
{
double temp;
temp=m;
m=n;
n=temp;
}
double** mult_row(double** q,double x1,int i1,int j1)
{
for(int u1=0;u1<(2*j1);u1++){
q[i1][u1]=q[i1][u1]*x1;
}
return q;
}
double** substract_row(double** w,int i2,int i3,int j2)
{
for(int v1=0;v1<(2*j2);v1++){
w[i2][v1]=w[i2][v1]-w[i3][v1];
}
return w;
}
double** swap_row(double** s,int i4,int i5,int j3)
{
double temp1;
for(int u2=0;u2<(2*j3);u2++){
temp1=s[i4][u2];
s[i4][u2]=s[i5][u2];
s[i5][u2]=temp1;
}
return s;
}
please what is the wrong in this code???
please can any one answer me quickly
the compiler gives me these errors :
d:\program files\microsoft visual studio\common\msdev98\bin\cppkos.cpp(10) : error C2062: type 'double' unexpected
d:\program files\microsoft visual studio\common\msdev98\bin\cppkos.cpp(12) : error C2062: type 'int' unexpected
d:\program files\microsoft visual studio\common\msdev98\bin\cppkos.cpp(13) : error C2630: ';' found in what should be a comma-separated list
d:\program files\microsoft visual studio\common\msdev98\bin\cppkos.cpp(34) : error C2065: 'swap_row' : undeclared identifier
d:\program files\microsoft visual studio\common\msdev98\bin\cppkos.cpp(34) : error C2440: '=' : cannot convert from 'int' to 'double ** '
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
d:\program files\microsoft visual studio\common\msdev98\bin\cppkos.cpp(44) : error C2440: 'return' : cannot convert from 'const int' to 'double ** '
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
d:\program files\microsoft visual studio\common\msdev98\bin\cppkos.cpp(65) : error C2065: 'rtg' : undeclared identifier
d:\program files\microsoft visual studio\common\msdev98\bin\cppkos.cpp(65) : error C2143: syntax error : missing ';' before 'return'
d:\program files\microsoft visual studio\common\msdev98\bin\cppkos.cpp(101) : error C2084: function 'double **__cdecl substract_row(double ** ,int,int,int) ' already has a body
d:\program files\microsoft visual studio\common\msdev98\bin\cppkos.cpp(108) : error C2373: 'swap_row' : redefinition; different type modifiers
but i am sure i made thses rights for example
in the error:
d:\program files\microsoft visual studio\common\msdev98\bin\cppkos.cpp(34) : error C2440: '=' : cannot convert from 'int' to 'double ** '
in this error i am sure that the left hand side is defined as double** & the right handside is defined also as double** so how could it be wrong so acn anyone help me quickly bacause i have to disscuss this project with my doctor the next saturday so i need help quickly
By the way this program is to compute the inverse of a square matrix (n*n) using gauss elimination
srry but ther are some wrong things not from but from the net after i wrote the message it doesnt appear but i dont know why as the for loops it seems that it is not complete but i wrote it competely ut it doesnt appear when i preview the message but i dont know why
|
|
|
|
|
kosamoza wrote:
ut it doesnt appear when i preview the message but i dont know why
Check 'Do not treat <'s as HTML tags' below the message window and repost your code, and I'll be happy to throw it into a project to see what's wrong with it.
|
|
|
|
|
This is an example of a situation where one typo causes cascading errors for your compiler. Your forward declaration of substract_row ends in a colon (: ). Change it to a semicolon (; ) and everything will compile OK.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
The pre was a good idea but:
1) Replace the '<' characters with the '&' character followed by 'lt' (sorry, but the do not treat as HTML tags seems to be broken).
2) Replace the '>' characters with the '&'
character followed by 'gt'.
The fact that your functions are all returning double**, shows a major flaw in the design of your code.
From what I am seeing the functions should probabley be following this pattern:
data_type funct(data_type* data, etc...)
{
return(data);
}
Another example:
double* input_mat(int x,int y)
{
matrix *pMat = new matrix(x);
return(pMat);
}
Try to figure out why your design is flawed, then repost (if you need too); after fixing the '<' and '>' characters so we can see what is between them (and so we can try to cut/copy the code).
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
#include <iostream>
#include <fstream>
using namespace std;
double** input_mat(int x,int y);
double** expand_mat(double** g,double** f,int d,int e);
void swap(double &m,double &n);
double** mult_row(double** q,double x1,int i1,int j1);
double** substract_row(double** w,int i2,int i3,int j2);
double** swap_row(double** s,int i4,int i5,int j3);
int main()
{
double** a;
double** b;
double** c;
int row,col;
cout<<"Enter the number of rows then coloumns of the matrix \n";
cin>>row>>col;
a=input_mat(row,col);
b=new double*[row];
for(int k=0;k<row;k++){
b[k]=new double[(2*col)];
}
b=expand_mat(a,b,row,col);
for(int j=0;j<col;j++){
if(b[(row-1)][j]!=0){
b=mult_row(b,b[(row-1)][j],(row-1),col);
for(int k=0;k<(row-1);k++){
b=mult_row(b,b[k][j],(row-1),col);
b=substract_row(b,k,(row-1),col);
}
b=swap_row(b,j,(row-1),col);
}
}
c=new double*[row];
for(int k1=0;k1<row;k1++){
c[k1]=new double[col];
}
ofstream out("Inverse");
if(!out){
cout<<"Cannot open file \n";
return 1;
}
for(int u=0;u<row;u++){
for(int v=0;v<(2*col);v++){
out<<b[u][v]<<endl;
}
}
out<<b[(row-1)][0]<<b[0][0]<<b[0][1]<<b[1][1];
return 0;
}
double** input_mat(int x,int y)
{
double** matrix;
matrix=new double*[x];
for(int i=0;i<x;i++){
matrix[i]=new double[y];
for(int j=0;j<y;j++){
cout<<"enter the element"<<j+1<<"in the row"<<i+1<<":";
cin>>matrix[i][j];
}
}
return matrix;
}
double** expand_mat(double** g,double** f,int d,int e)
{
for(int i=0;i<d;i++){
for(int j=0;j<e;j++){
f[i][j]=g[i][j];
}
}
for(int u=0;u<d;u++){
for(int v=e;v<(2*e);v++){
if((u+e)==v){
f[u][v]=1;
}else{
f[u][v]=0;
}
}
}
return f;
}
void swap(double &m,double &n)
{
double temp;
temp=m;
m=n;
n=temp;
}
double** mult_row(double** q,double x1,int i1,int j1)
{
for(int u1=0;u1<(2*j1);u1++){
q[i1][u1]=q[i1][u1]*x1;
}
return q;
}
double** substract_row(double** w,int i2,int i3,int j2)
{
for(int v1=0;v1<(2*j2);v1++){
w[i2][v1]=w[i2][v1]-w[i3][v1];
}
return w;
}
double** swap_row(double** s,int i4,int i5,int j3)
{
double temp1;
for(int u2=0;u2<(2*j3);u2++){
temp1=s[i4][u2];
s[i4][u2]=s[i5][u2];
s[i5][u2]=temp1;
}
return s;
}
i have changed':' to ';' and it gives no error in the compilation but it gives the same prop;ems durin executing the programwhy?????
|
|
|
|
|