|
Nope it crashes and burns as you would expect given the warnings.
I wasn't going to debug a whole pile of code which I assumed was your homework.
In vino veritas
|
|
|
|
|
It is strange that you had to assume this was homework when I explicitly stated that it was on more than one occasion.
|
|
|
|
|
You said and I quote it exactly
"To clarify, this is an assignment I am working on."
"The arrays were set by the instructor, believe it or not, and I am not allowed to modify them."
So are you telling me this isn't a homework assignment for a programming unit?
University assignments are about you learning not someone on the network doing them for you. Secondly I am not allowed to correct somethings like the array creation obviously so how would I know what I can and can not correct?
I feel confident any normal person would assume what I have and if it comes as a shock to you well sorry it is logical.
We could go into how you reconcile those statements with it not being a homework assignment but lets just ignore that and move on.
All I can say is the current code crashes and burns beautifully at the moment which is entirely predictable.
So to even help at the moment I need to know what code I am allowed to change and what I can't which you clearly know but I have no clue.
Do you at least see and agree I need to know what is allowed to be changed?
In vino veritas
modified 21-Mar-18 22:52pm.
|
|
|
|
|
1. So what you are telling me is that you thought the term "assignment" DID NOT mean "homework"? My mentioning the instructor didn't help you form the conceptual link between the two terms?
2. I specified that I can make changes to specific portions of the code. It is common for instructors to provide sample code and ask for changes to specific segments.
3. When I encounter a problem that I can't overcome, should I simply give up or try my hand at whatever resources I have at my disposal, including online forums? Do you advocate that I simply give up and not learn at all?
To clarify, I worked out how to do memory tiling in the kernel. Perhaps your unjustifiably obnoxious behaviour helped me solve this and for that I am grateful.
Lastly, you made a big fuss about the memory allocation segment when you could have simply said "Ehm, did you forget the asterisk?". People like you make online forums absolutely TOXIC and you should be ashamed of yourself.
modified 2-Apr-18 4:02am.
|
|
|
|
|
I am not going to make the situation worse but I would like you to go thru it as an exercise
Your Point 1> I still have no idea what you are saying, I think you are objecting to me referring to assignment as homework is that the issue?
Your Point 2> I understood your point but I have no idea what code belongs to your lecturer and which belongs to you?
Your Point 3> No use online forums but remember we are not mind readers, things that may be obvious to you are not to us.
You may care to review the conversation and consider I may not be clear exactly what you are trying to do. I also took the time to write code and give you my best guess at an answer which is hardly the actions of someone trying to be "unjustifiably obnoxious" and I took the time to answer each of your responses.
You may care to review the sticky, points 5 & 11 are very pertinent
HOW TO ASK A QUESTION - C / C++ / MFC Discussion Boards[^]
I actually didn't and still don't know if it was just missing an asterix because there are multiple problems as none of the types matched up. It is the same as structs being rolled in as strings in variadic printf statements, it's hard to work out what was intended. This rolls back to point 5 on the HOW TO ASK A QUESTION sticky.
I am sorry you feel I was being toxic that was definitely not my intent and if that belief spurred you to solve the problem at least that was a positive and hopefully you will be more careful with postings in future.
In vino veritas
modified 3-Apr-18 1:17am.
|
|
|
|
|
Oh ok. I see the mix up. I forgot to add the * in my original post. Of course I am initializing a pointer to dynamically allocated memory.
unsigned long long *A = new unsigned long long[n*n/64];
unsigned long long *B = new unsigned long long[n*n/64];
int C = new int[n*n];
|
|
|
|
|
Well, you should always copy/paste your original code snippets, not just type it here from scratch!
|
|
|
|
|
I am using RHEL6, Qt4.8.5, QTCreator
I am using the command line entry
Quote: soffice --invisible -convert-to csv excelfilename.xls
It works fine but only give me the first spreadsheet tab in the workbook. Does anyone know how to drill down to the subsequent spreadsheets using this command line entry??
Thanks
emp
|
|
|
|
|
|
|
Using any MPI library, how do I configure the settings and build a mpi.h file (Can be a library from the Intel MPI or Open MPI) that I can use with the Linux C++ in VS?
|
|
|
|
|
|
Cant use it, I asked the Microsoft MPI guys, and MSMPI only targets Windows. So in order to use MPI on Linux machines, you have to use some other MPI implementation, like Open MPI or Intel MPI.
|
|
|
|
|
I guess the easy way then is don't cross it ... compile it under a linux distro.
Is there any specific reason you wanted to cross it from Visual Studio?
In vino veritas
|
|
|
|
|
I want to be able to use the same MPI C++ code from both Windows and Linux, as it would effectively cut development time in half (its a rather complicated project).
|
|
|
|
|
Hi,
I've never done this. However I don't see any reason for this not to work.
Try following the instructions here using gendef and dlltool for generating the Linux shared lib with the MinGW-w64 Cross-Compiler.
TUTORIAL: Adapting MS-MPI for MinGW64[^]
Ignore the fact that the tutorial is for GFortran. The lib portion of the tutorial is what you need.
I am almost positive this should work... allowing you to have a single code base that compiles for both Windows and Linux.
Best Wishes,
-David Delaune
|
|
|
|
|
If I read you correctly I can configure VS2017 using MinGW-w64 as the compiler instead of g++?
|
|
|
|
|
Yes.[^]
If you spend some time setting this up... you will also only need 1 workstation to do the entire project. You can run your Linux binary on Windows Linux Subsystem.
Install the Linux Subsystem on Windows 10 | Microsoft Docs[^]
Spending 1/2 days setting this up may save you weeks in the long run... you can avoid multiple OS installations... multiple compilers... and do all your work in Visual Studio on Windows.
Best Wishes,
-HAL 9000
|
|
|
|
|
#include <iostream>
#include <cstring>
using namespace std;
class st{
char *p;
int len;
public:
st(){len=0; p=0;}
st(const char *s);
st(const st &s);
~st(){delete p;}
friend st operator + (const st &, const st &);
friend int operator <= (const st &, const st &);
friend void show(const st);
};
st :: st(const char *s){
len = strlen(s);
p = new char[len+1];
strcpy(p, s);
}
st :: st(const st &s){
len = s.len;
p = new char[len+1];
strcpy(p, s.p);
}
st operator + (const st &s, const st &t){
st temp;
temp.len = s.len + t.len;
temp.p = new char[temp.len + 1];
strcpy(temp.p, s.p);
strcat(temp.p, t.p);
return(temp);
}
int operator <= (const st &s, const st &t){
int m = strlen(s.p);
int n = strlen(t.p);
if(m <= n) return(1);
else return(0);
}
void show(const st s){
cout<<s.p;
}
int main(){
st s1 = "New ";
st s2 = "York";
st s3 = "Delhi";
st string1, string2, string3;
string1 = s1;
string2 = s2;
string3 = s3+s1;
cout<<"\nstring1 = "; show(string1);
cout<<"\nstring2 = "; show(string2);
cout<<endl;
cout<<"\nstring3 = "; show(string3);
cout<<"\n\n";
if(string1 <= string2){
show(string1); cout<<" smaller than "; show(string2);
cout<<endl;
}else {
show(string2); cout<<" smaller than "; show(string2);
cout<<endl;
}
return 0;
}
This program works fine when i replace
Quote: st string1, string2, string3;
with
Quote: st string1=s1, string2=s2, string3=s1+s3;
so what's the problem, i learned in class that we can pass the values in the constructor by calling it explicitly, and (string1, string2, string3) & (s1, s2, s3) have same return type i.e.class st.
So why isn't it working ?
thank you
|
|
|
|
|
To make this part of code working:
st string1, string2, string3;
string1 = s1;
string2 = s2;
you must implement the assignment operator for your class st.
|
|
|
|
|
As Victor Nijegorodov noted, your code violates the rule of three[^]: you have to define the assignment operator.
|
|
|
|
|
Hi Everyone.
I'm new to the site and new to C++. I'm coming from a background in VB and database admin.
I've got a console app which is trying to connect to an MS Access database and I'm having a terrible time trying to make this happen. All I'm trying to do here is execute a simple SQL SELECT statement and have the results come back.
The code below compiles just fine and runs fine but it keeps telling me it can't connect to the data source. I'm using VS 2017 and I've been able to set up a data connection which tests successfully every time. I've done my best to make sure I have all the correct drivers and other connection dlls. I'm a bit confused as to how I can have a successful connection within the VS environment (meaning I can browse tables, make queries, etc in VS) but I can't connect in my code. I've tried to copy and paste the 'build connection string' when I built the data connection and I also tried to reference the connection by name and no luck so far.
Thanks for your help!
Brennan
#include "stdafx.h"
#include<iostream>
#include <Windows.h>
#include <sql.h>
#include <sqltypes.h>
#include <sqlext.h>
#include <comutil.h>
#include <winerror.h>
SQLCHAR* dsnName = (SQLCHAR*)"Driver={Microsoft Access Driver (*.mdb, *.accdb)};dbq=C:\Program Files\MyTrading\DTP\DTP_DB.accdb;defaultdir=C:\Program Files\MyTrading\DTP;driverid=25;fil=MS Access;filedsn=C:\Program Files\MyTrading\DTP\DTP_DB.accdb.dsn;maxbuffersize=2048;maxscanrows=8;pagetimeout=5;safetransactions=0;threads=3;uid=admin;usercommitsync=Yes";
#define db "C:\\Program Files\\MyTrading\\DTP\\DTP_DB.accdb"
using namespace std;
int main()
{
const char* DAM = "Direct ODBC";
HENV hEnv;
HDBC hDbc;
RETCODE rc;
int iConnStrLength2Ptr;
char szConnStrOut[256];
SQLWCHAR* strSQL = (SQLWCHAR*)"SELECT Exchanges.[X Name], Exchanges.[X Full Name] FROM Exchanges;";
SQLCHAR chval1[128], chval2[128];
SQLWCHAR colName[128];
int ret1;
int ret2;
SQLINTEGER rowCount = 0;
SQLSMALLINT fieldCount = 0, currentField = 0;
HSTMT hStmt;
rc = SQLAllocEnv(&hEnv);
rc = SQLAllocConnect(hEnv, &hDbc);
rc = SQLDriverConnect(hDbc, NULL, (wchar_t*)dsnName, SQL_NTS, (wchar_t*)szConnStrOut, 255, (SQLSMALLINT*)&iConnStrLength2Ptr, SQL_DRIVER_NOPROMPT);
if (SQL_SUCCEEDED(rc))
{
printf("%s: Successfully connected to database. Data Source Name: \n %s\n",
DAM, szConnStrOut);
printf("%s: SQL query:\n %s\n", DAM, strSQL);
rc = SQLAllocStmt(hDbc, &hStmt);
rc = SQLPrepare(hStmt, strSQL, SQL_NTS);
rc = SQLBindCol(hStmt, 1, SQL_C_CHAR, chval1, 128, (SQLLEN*)&ret1);
rc = SQLBindCol(hStmt, 2, SQL_C_CHAR, chval2, 128, (SQLLEN*)&ret2);
rc = SQLExecute(hStmt);
if(SQL_SUCCEEDED(rc))
{
printf("%s: Retrieve schema info for the given result set :\n", DAM);
SQLNumResultCols(hStmt, &fieldCount);
if (fieldCount > 0)
{
for (currentField = 1; currentField <= fieldCount; currentField++)
{
SQLDescribeCol(hStmt, currentField, colName, sizeof(colName), 0, 0, 0, 0, 0);
printf(" | %s", colName);
}
printf("\n");
}
else
{
printf("%s: Error: Number of fields in the result set is 0.\n", DAM);
}
printf("%s: Fetch the actual data:\n", DAM);
rc = SQLFetch(hStmt);
while (SQL_SUCCEEDED(rc))
{
printf(" \ %s | %s\n", chval1, chval2);
rc = SQLFetch(hStmt);
rowCount++;
};
printf("%s: Total Row Count: %d\n", DAM, rowCount);
rc = SQLFreeStmt(hStmt, SQL_DROP);
}
}
else
{
printf("%s: Couldn't connect to %s.\n", DAM, dsnName);
}
SQLDisconnect(hDbc);
SQLFreeHandle(SQL_HANDLE_DBC, hDbc);
SQLFreeHandle(SQL_HANDLE_ENV, hEnv);
printf("%s: Cleanup. Done.\n", DAM);
return 0;
}
|
|
|
|
|
Any particular reason you chose to start with c++?
C# and VB.Net will provide a lot more examples of what you're after; particularly when it comes to Access.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Can you use MFC?
With CDatabase and CRecordset classes your DB access would be more easy and simple!
|
|
|
|
|
Don't recommend MFC for new developments the framework is going to become increasingly problematic now it's out of support and cracks have already opened up with current updates of Windows 10.
If you really feel it would be good to use at least make them aware of the issue going forward.
In vino veritas
modified 15-Mar-18 23:20pm.
|
|
|
|
|