所以我有这个程序在我的家用机器上编译很好,但是一旦我在大学服务器上编译它就会打破......:/这对我的屁股来说是一个巨大的痛苦.我不知道可能导致错误的位置或原因.我首先从大学的valgrind报告开始.
    ==13527== Memcheck, a memory error detector
==13527== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==13527== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==13527== Command: ./main stock.dat coins.dat
==13527== 
==13527== Invalid write of size 8
==13527==    at 0x402762: load_data (in /RMIThome/shr/5/s3234575/Assignments2/main)
==13527==    by 0x4028BE: main (in /RMIThome/shr/5/s3234575/Assignments2/main)
==13527==  Address 0x6172676f72502074 is not stack'd, malloc'd or (recently) free'd
==13527== 
==13527== 
==13527== Process terminating with default action of signal 11 (SIGSEGV)
==13527==  General Protection Fault …所以我有这个带有函数的代码,它应该将二维数组中的所有数字打印到二次幂,但我的代码不断抛出分段错误,我不知道为什么
#include <bits/stdc++.h>
using namespace std;
void er(int arr[][100000000], int, int);
int main()
{
    int n, m;
    cin >> n >> m;
    int arr[n][100000000];
    er(arr, n, m);
    return 0;
}
void er(int arr[][100000000], int n, int m)
{
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> arr[i][j];
            arr[i][j] *= arr[i][j];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = …为了解决我的问题在这里,我想知道是否/如何我可以比在格式定义的命令行参数的第二个变量其他char** argv或char* argv[]。原因是 pybind11 不允许函数输入中的任何一个。以下是我尝试过的方法:
#include <stdio.h>
int main(int argc, int* argv_){
    for (int i = 0; i < argc; ++i){
        printf("%s\n", (char *)(argv_[i]));
    }
}
这种方法背后的基本原理是指针本质上是一个整数,通过将地址转换为char指针,人们应该能够获得字符串。提前感谢您的支持。
#include <stdio.h>
#include <string>
int main(int argc, std::string* argv_){
    for (int i = 0; i < argc; ++i){
        printf("%s\n", argv_[i].c_str());
    }
}
#include <stdio.h>
#include <string>
#include <vector>
int main(int argc, std::vector<std::string> argv_){
    for (int i = 0; i < …这是提交之间的区别,只是注释和行间距不同,但旧的提交正常运行,而新的结果导致段错误:
Binary files a/recover/recover and b/recover/recover differ
diff --git a/recover/recover.c b/recover/recover.c
index f0ffdf6..02ab42b 100644
--- a/recover/recover.c
+++ b/recover/recover.c
@@ -1,34 +1,32 @@
-#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <string.h>
 
 typedef enum
 {
-   false,
-   true
-} bool;
+   true,
+   false
 
-typedef uint8_t BYTE;
+} bool;
 
 typedef char *string;
 
+typedef uint8_t BYTE;
 int BLOCK_SIZE = 512;
 
 int main(int argc, char *argv[])
 {
-   // Check if a file name was provided as an argument
-   if …在这个程序这里:
#include <stdio.h>
int main(void)
{
    char ch = 'A';
    char* ptr = &ch;
    ptr[8] = 'B';
    printf("ptr[8] = %c\n", ptr[8]);
    *ptr = 'C';
    printf("*ptr = %c\n", *ptr);
}
输出:
ptr[8] = B
*ptr = C
Segmentation fault (core dumped)
我认为该程序应该在行ptr[8] = 'B';和段崩溃,但程序确实执行了所有代码行然后崩溃,这是我真的没有得到的.
它不应该在线路上崩溃ptr[8] = 'B';并停止执行吗?