c

Split String in C to recognize consecutive tabs

巧了我就是萌 提交于 2021-02-17 04:31:12
问题 I have a file that has certain fields separated by tabs. There will always be 17 tabs but there order can vary, such as.. 75104\tDallas\t85\t34.46\t45.64 75205\tHouston\t\t37.34\t87.32 93434\t\t\t1.23\t3.32 When I use strtok in the following fashion while (fgets(buf, sizeof(buf), fp) != NULL) { tok = strtok(buf,"\t"); while(tok != NULL) { printf("%s->",tok); tok = strtok(NULL,"\t"); } } I get all the tokens, but double tabs \t\t or more are ignored. However, I need to know when a field is

How to prevent gdb to stop after next command

房东的猫 提交于 2021-02-17 04:01:10
问题 I am trying to define a chain of commands, which shall be invoked after a breakpoint in gdb: break some_function commands up next printf "some_string" continue end In this case (for example) I want to break at some_function, go up in the stack frame and jump right behind this function via the next command, then print "some_string" (or maybe some variable, which was changed by the function) and then just to continue. But that doesn't work, since gdb will just stop after the next command and

How to prevent gdb to stop after next command

故事扮演 提交于 2021-02-17 04:00:14
问题 I am trying to define a chain of commands, which shall be invoked after a breakpoint in gdb: break some_function commands up next printf "some_string" continue end In this case (for example) I want to break at some_function, go up in the stack frame and jump right behind this function via the next command, then print "some_string" (or maybe some variable, which was changed by the function) and then just to continue. But that doesn't work, since gdb will just stop after the next command and

insmod: ERROR: could not insert module kernel.ko: Invalid parameters - Error related to naming scheme of kernel module

霸气de小男生 提交于 2021-02-17 03:56:07
问题 I'm using C to create a custom kernel module to hook into the netfilter operation on my Ubuntu box. However, I'm running into a problem revolving around the module_param argument. When inserting the module, I'm attempting to add a custom field, specifically this will drop ICMP traffic when specified. The code compiles fine using a standard make file but when using insmod to insert it, I get the error insmod: ERROR: could not insert module kernel.ko: Invalid parameters I'm using the command

Suggestions for beginning steps to build a calendar program in C [closed]

混江龙づ霸主 提交于 2021-02-17 03:45:15
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . Improve this question I am working on a practice project of my school, which is to build a C program that resembles a calendar in linux or Mac command lines. The program doesn't have to implement all the methods that a calendar has, but it should produce the same output for these

Suggestions for beginning steps to build a calendar program in C [closed]

拜拜、爱过 提交于 2021-02-17 03:44:17
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . Improve this question I am working on a practice project of my school, which is to build a C program that resembles a calendar in linux or Mac command lines. The program doesn't have to implement all the methods that a calendar has, but it should produce the same output for these

Unable to correctly write data in a text file

末鹿安然 提交于 2021-02-17 03:43:05
问题 I wrote the following program to print 200 random number in a file: int main() { FILE * fp; fp = fopen ( "myfile.txt", "w" ) ; if ( fp == NULL ) { printf ( "Unable to create file." ) ; exit ( 0 ) ; } int i, noofr=200, j ; for ( i = 0 ; i < noofr ; i++ ) { j = rand ()%100 ; fwrite ( &j, sizeof ( int ), 1, fp ) ; printf ( "%d\t", j ) ; } fclose ( fp ) ; printf ( "\nFile is created. \nPress any key to continue." ) ; return 0; } On the console the number are printing correctly, but in the file, I

scanf is using an uninitialized variable; C [duplicate]

霸气de小男生 提交于 2021-02-17 03:29:51
问题 This question already has answers here : why scanf scans a null value (2 answers) Closed 6 years ago . I'm sure there just a silly mistake here, however, I can't figure it out. This is part of my code: char *moving; scanf("%s", moving); When I compile it with gcc, it says the following: newmatrix.c:38:7: warning: ‘moving’ is used uninitialized in this function [-Wuninitialized] Line 38 is the scanf How do I fix this? Thanks 回答1: Allocate memory for moving before using it. Use malloc() .

OpenMP not waiting all threads finish before end C program

我怕爱的太早我们不能终老 提交于 2021-02-17 03:19:36
问题 I have the following problem: My C program must count the number of occurrences of a list of words in a text file. I use OpenMP for this, and the program, in theory, has the correct logic. When I put some printfs inside a For Loop the result of the program is correct and always the same. When I remove printfs the result is incorrect, and with each execution its value changes. Given this scenario I think the reason is related to the execution time. With printfs the execution time is increased,

Calling a Function from a String in C

≡放荡痞女 提交于 2021-02-17 02:44:05
问题 In C, how to do you call a function from just having its name as a string? I have this: int main(int argc, const char *argv[]) { char* events[] = { "test", "test2" }; int i = 0; for (; i < 2; ++i){ char* event = events[i]; // call function with name of "event" } return 0; } 回答1: You can do it, but there's not much built-in to help out. typedef struct { char *event_name; void (*handler)(); } event_handler; then search through an array (or whatever) of event_handler s, and when you find the