我正在使用此代码获得分段错误,即使这两个文件每个都有2 ^ 14个值.谁能告诉我原因.
#define N 128
#include<stdio.h>
#include <malloc.h>
int A[N][N];
int B[N][N];
int C[N][N];
void mmul();
int main()
{
int p,q;
FILE *fp;
fp=fopen("A.txt","r");
if(fp=NULL)
printf("Error\n");
printf("A");
for(p=0;p<(1<<7);p++)
{
for(q=0;q<(1<<7);q++)
{
fscanf(fp, "%d", &A[p][q]);
}
}
fclose(fp);
fp=fopen("B.txt","r");
if(fp=NULL)
printf("Error\n");
for(p=0;p<(1<<7);p++)
{
for(q=0;q<(1<<7);q++)
{
fscanf(fp, "%d", &B[p][q]);
}
}
fclose(fp);
printf("here");
mmul();
}
void mmul()
{
int i,j,k;
unsigned int sum;
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
sum=0;
for(k=0;k<N;k++)
{
sum=sum+(A[i][k]*B[k][j]);
}
C[i][j]=sum;
}
}
}
Run Code Online (Sandbox Code Playgroud) 当我在QtCreator上运行代码时,我得到了:
08:23:56: Running steps for project dialog...
08:23:56: Configuration unchanged, skipping qmake step.
08:23:56: Starting: "/usr/bin/make" -w
make: Entering directory `/home/entel/program/c++/dialog-build-Desktop_Qt_5_0_1_GCC_32bit-Debug'
g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/opt/Qt5.0.1/5.0.1/gcc/mkspecs/linux-g++ -I../dialog -I/opt/Qt5.0.1/5.0.1/gcc/include -I/opt/Qt5.0.1/5.0.1/gcc/include/QtWidgets -I/opt/Qt5.0.1/5.0.1/gcc/include/QtGui -I/opt/Qt5.0.1/5.0.1/gcc/include/QtCore -I. -I. -I. -o dialog.o ../dialog/dialog.cpp
../dialog/dialog.cpp: In constructor 'FindDialog::FindDialog(QWidget*)':
../dialog/dialog.cpp:5:40: error: invalid use of incomplete type 'class QLabel'
In file included from ../dialog/dialog.cpp:1:0:
../dialog/dialog.h:9:7: error: forward declaration of 'class QLabel'
../dialog/dialog.cpp:6:20: error: invalid use of incomplete type 'class QLineEdit' …
Run Code Online (Sandbox Code Playgroud) 这几天我发布了一些与此问题相关的问题.只有这一点,现在我得到了一些非常有趣
看看我的代码:
#include <libpq-fe.h>
#include <stdlib.h>
#include <string.h>
#define LINE_SIZE 100
PGconn *connect(char *);
int main()
{
connect("/path/to/file.props");
return 0;
}
PGconn *connect(char *file_path)
{
const char **keywords;
const char **values;
char *line = malloc(LINE_SIZE);
char *prop, *val, *tmp;
int i = 0, j = 0, k = 0;
PGconn *conn = NULL;
FILE *creds = fopen(file_path, "r");
if (creds == NULL) {
perror("error: cannot open credentials file"); //!!! warning
exit(1);
}
keywords = malloc(6 * sizeof(char *));
values = …
Run Code Online (Sandbox Code Playgroud) 我不经常使用C或C++,但我即将完成编译一个用opencv检测面部的文件,这是一个已经为windows做的c ++文件的副本,用于在社交网络中进行标记,错误我编译时获取代码是下一个
In function 'main':
warning: assignment from incompatible pointer type
Run Code Online (Sandbox Code Playgroud)
int main( int argc, char** argv[])
{
char* dea;
int i=0;
while(i<argc)
{
if(i==1){
dea=argv[i];
}
i++;
}
char image[400],temp_image[400];
IplImage *img,*temp_img;
int key;
storage = cvCreateMemStorage( 0 );
cascade = ( CvHaarClassifierCascade* )cvLoad( face_cascade, 0, 0, 0 );
if( !(cascade) )
{
fprintf( stderr, "ERROR: Could not load classifier cascade\n" );
return -1;
}
sprintf(image,"dimage%d.jpg");
img=cvLoadImage(dea,0);
temp_img=cvLoadImage(dea,0);
if(!img)
{
printf("Could not load image file and trying once again: …
Run Code Online (Sandbox Code Playgroud) 由向量携带的是一对由id索引的对:
<std::pair<int, std::pair<int, int>>>
496 1, 256
(message id)
Run Code Online (Sandbox Code Playgroud)
如您所见,"id"是重复的.为了进一步处理这些数据,对我来说,根据"消息ID"对三元组进行排序对逻辑非常有用.如何使用STL函数执行此操作?
这是一些数据样本:
15:38:08.307 - (I) ET02 - For message Id: 496 Tag - value pair: 1 - 256
15:38:08.307 - (I) ET02 - For message Id: 496 Tag - value pair: 2 - 27060
15:38:08.307 - (I) ET02 - For message Id: 496 Tag - value pair: 3 - 2014-06-16T17:07:00.519
15:38:08.307 - (I) ET02 - For message Id: 487 Tag - value pair: 1 - 1044
15:38:08.307 - (I) ET02 - …
Run Code Online (Sandbox Code Playgroud) 我有一个使用std字符串参数来测试是否有字母字符的函数。最好只测试数字字符,但到目前为止我还没有得到。我只是想让它识别输入中是否没有数字。如果不是,它将循环显示错误消息,直到只有数字为止。在此之后,我尝试使用atof()将字符串转换为double,以便可以在main()中返回它。我得到调试断言失败!运行时的消息,其中说,如果输入数字,则表达式字符串下标超出范围。否则,如果输入了字母,它将继续使用错误消息循环其自身。我得到了下面函数的代码。有人对我做错了什么有任何线索吗?我没主意...
double Bet::betProb(std::string b)
{
bool alphChar = false;
double doubleBet;
for(int i = 0; i < b.size(); i++){
if(isalpha(b[i])){
alphChar = true;
}
}
while(alphChar){
cout << "Error! Bet only with numbers." << endl;
cin >> b;
for(int i = 0; i < b.size(); i++){
if(!isalpha(b[i])){
alphChar = false;
}
}
}
string F=b;
int T=F.size();
char Change[100];
for (int a=0;a<=T;a++)
{
Change[a]=F[a];
}
doubleBet = atof(Change);
return doubleBet;
}
Run Code Online (Sandbox Code Playgroud) 当我运行我编写的以下程序时,我得到运行时检查失败#2-变量'NewImage'周围的堆栈已损坏.我怎样才能解决这个问题?我知道它与更改内存限制有关,但我不知道要改变什么.谢谢!
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int ROWS = 16;
const int COLS = 16;
enum flipType {HORIZONTAL, VERTICAL};
enum rotateType {CLOCKWISE, COUNTER_CLOCKWISE};
void getImage(char img[][COLS]);
void print(const char img[][COLS], string msg);
void flip(const char img[][COLS], char NewImage[][COLS], flipType);
void negative(const char img[][COLS], char NewImage[][COLS]);
void rotate(const char img[][COLS], char NewImage[][COLS], rotateType);
int main()
{
char Image[ROWS][COLS];
char NewImage[ROWS][COLS];
getImage(Image);
// print the original image
print(Image, "Original Image");
getImage(NewImage);
flip(Image, NewImage, VERTICAL);
print(NewImage, "Vertically Flipped …
Run Code Online (Sandbox Code Playgroud) 我的编译器在此代码中给出了"无法找到'ostream :: write(S1,int)'的匹配项"的错误.编译器发出错误的部分被注释
#include<iostream.h>
#include<stdlib.h>
int main()
{
struct S1
{
char*str;
S1*ptr;
};
S1 arr[]={" Aanna ",arr+1," Neha ",arr+2," Simran ",arr};
S1*p[3];
for(int i=0;i<3;++i)
p[i]=arr[i].ptr;
cout.write(p[0]->str,7).put('\n');
cout.write((*p)->str,7).put('\n');
cout.write(**p,7).put('\n');//why doesn't it work
return 0;
}
Run Code Online (Sandbox Code Playgroud) int **dpTable = new int* [iMatrixHeight + 1];
for (int i = 0; i < iMatrixHeight + 1; i++)
{
dpTable[i] = new int [iMatrixWidth + 1];
}
memset(dpTable, 0, (sizeof(int)) * (iMatrixHeight + 1)*(iMatrixWidth + 1));
Run Code Online (Sandbox Code Playgroud)
我正在使用operator new来分配一个二维数组,但是如果我使用memset来初始化数组,那么当我稍后访问数组时,我得到了一个段错误.没有memset,没关系.
我做错了吗?谢谢!
我有一个十六进制值的字符指针,如下所示.a = {0x01,0x02,0x00,0x03,0x04,0x05,0x00}; 我必须找到上面数组的长度.但是strlen给出2并且sizeof给出4(char指针大小).我怎样才能找到长度?我从套接字接收字符数组.