segmentation-fault

need help solving a segmentation fault with file i/o in C

泄露秘密 提交于 2019-12-24 15:36:44
问题 I read the input file , which has 911 lines , and want to copy these 911 lines into the output file , after making a few changes to each line.. I am getting segmentation fault when i run this.. I dont know why.. can anyone please help.. #include<stdio.h> void main() { int i; FILE *fin,*fop;char* str; fin=fopen("atk561011.txt","r"); if(fin=NULL) printf("ip err"); fop=fopen("svmip.txt","w"); if(fop=NULL) printf("op err"); for(i=1;i<=911;i++) { fgets(str,150,fin); if((i>300&&i<=360)||(i>600&&i<

What actually prints “Segmentation fault”?

為{幸葍}努か 提交于 2019-12-24 14:00:42
问题 Which binary or piece of code is printing Segmentation fault on the console when an error occurs? 回答1: That's the invoking shell's job, when job control is enabled. Demonstration with bash: $ set +m # disable job control $ bash -c 'kill -SEGV $$' $ set -m # enable job control $ bash -c 'kill -SEGV $$' Segmentation fault (core dumped) 来源: https://stackoverflow.com/questions/32564735/what-actually-prints-segmentation-fault

Mysterious Seg Faults with Cudamalloc

余生长醉 提交于 2019-12-24 13:25:58
问题 Can anyone help me to understand why the following code causes a segmentation fault? Likewise, can anyone help me understand why swapping out the two lines labelled "bad" for the two lines labelled "good" does not result in a segmentation fault? Note that the seg fault seems to occur at the cudaMalloc line; if I comment that out I also do not see a segmentation fault. These allocations seem to be stepping on each other, but I don't understand how. The intent of the code is to set up three

Seg fault with iterators in a recursive function

烂漫一生 提交于 2019-12-24 13:19:08
问题 I'm trying to sort integers in a vector using a recursive function. My program runs, compiles, and sorts the data, but after the fact it gives me a seg fault. I think its because of the for loop using the addresses in the vector that have been changed causing it to never leave the loop. void Plays::SortRelevance(vector<Plays> list){ cout << "in the loop" << endl; for(vector<Plays>::iterator i=list.begin(); i != list.end(); ++i){ cout << i->relevance << endl; } for(vector<Plays>::iterator i

Segmentation fault when reading a binary file into a structure

北慕城南 提交于 2019-12-24 12:11:44
问题 I'm experiencing some problems while trying to read a binary file in C. This problem never happened to me before, I don't really know how to manage it. So, there's this structure called "hash_record", there are many of them stored in my "HASH_FILE" file in binary mode. This is the structure: typedef struct hash_record { char *hash; char *filename; } hash_record; I write the file in this way: hash_record hrec; [...] code that fill the structure's fields [...] FILE* hash_file = fopen(HASH_FILE,

map with string is broken?

醉酒当歌 提交于 2019-12-24 11:54:12
问题 Yes. I can't see what I'm doing wrong. The map is: string, int Here's the method bange::function::Add(lua_State *vm){ //userdata, function if (!lua_isfunction(vm, 2)){ cout << "bange: AddFunction: First argument isn't a function." << endl; return false;} void *pfunction = const_cast<void *>(lua_topointer(vm, 2)); char key[32] = {0}; snprintf(key, 32, "%p", pfunction); cout << "Key: " << key << endl; string strkey = key; if (this->functions.find(strkey) != this->functions.end()){ luaL_unref(vm

mysql_init(NULL) segmentation fault

天涯浪子 提交于 2019-12-24 11:16:05
问题 I have the following function: int get_tcounter(char *meterType, int *error) { MYSQL *conn = mysql_init(NULL); get_connection(conn, DB_HOST, DB_USER, DB_PW, DB); MYSQL_STMT *stmt = mysql_stmt_init(conn); if (!stmt) { log_to_console("Init stmt failed: %s\n", mysql_error(conn)); exit(1); } prepare_stmt(conn, stmt, GET_TCOUNTER_SQL); MYSQL_BIND param[1], res[1]; memset(param, 0, sizeof(param)); memset(res, 0, sizeof(res)); char *paramBuff; int tcBuff; my_bool isNullParam[] = {0}, isNullRes[] =

Weird C++ bug, program works fine when 2 print statements are added, segfaults without them

十年热恋 提交于 2019-12-24 10:56:44
问题 I am writing some code in C++ that has to compute lots of ray/object intersections and I'm getting a very weird bug that I don't understand. On some very large instances (lots of triangles and rays) my program segfaults. I've been trying to figure out the source of these segfaults but I've been stumped. I've looked through my code and it doesn't seem like I should ever try to index off the end of an array or access a null pointer. It also doesn't seem like my computer is running out of memory

C++ Splitting the input problem

那年仲夏 提交于 2019-12-24 10:20:07
问题 I am being given input in the form of: (8,7,15) (0,0,1) (0,3,2) (0,6,3) (1,0,4) (1,1,5) (2,1,6) (2,2,7) (2,5,8) (3,0,9) (3,3,10) (3,4,11) (3,5,12) (4,1,13) (4,4,14) (7,6,15) where I have to remember the amount of triples there are. I wrote a quick testing program to try read the input from cin and then split string up to get the numbers out of the input. The program doesn't seem to read all the lines, it stops after (1,1,5) and prints out a random 7 afterwards I created this quick testing

Boost graph segmentation fault

荒凉一梦 提交于 2019-12-24 10:15:19
问题 I am trying to use Boost to embed a planar graph using the Chrobak-Payne algorithm. I am able to run the example successfully, but when I try to modify it and use different graphs it does not work correctly. I am trying to embed the second platonic graph but it does not work, and my code crashes with "Segmentation fault: 11". I assumed it is because I needed to use make_connected, make_biconnected_planar, and make_maximal_planar, but adding them did not fix it. Here is the modified source