question
stringlengths
25
894
answer
stringlengths
4
863
I would like to use OO/LO PDF generation capabilities in my applications. To do it, I need to be able to modify a previously generated odt template from my code. The modification would be simple text replacements only (which do not even require regexes). OO's developer's guidedoes not contain any examples or tutorial...
I ended up extracting the archive, processing and editing xml, then packing it back up again. Worked well.
I'm trying to divide the interval*[a,b]* in *npt*points saved in an array of float variables. I need that*a* and *b*be always present in the final array and that*npt*can be a varied as I want. I tried with: ``` delta = (b - a) / ((double) npt); for (i = 0; i < npt; i++) { x[i] = a + i * delta; } ``` But it doe...
If you havenptpoints you will havenpt-1intervals. Change the first line into: ``` delta=(b-a)/(npt-1.0); ```
In windows performance monitor there is an option to createData collector sets. Now is there any way to create a data collector set programmatically and read the log later from a C or C++ program(is there any specific api that i can do this)?
You can use the "Performance Logs and Alerts" (PLA) of Microsoft. With PLA you can create your own Data collector sets and work with existing ones. Collected Data may be saved in a .csv file, which can be evaluated with c or C++ algorithms
I want to write a C program that will display a name on the screen fifteen times. The program does not allow a loop. No WHILE, No DO WHILE, and No FOR LOOPS. You can only have one printf statement within the code. The output will look as follows: CakeCakeCakeCakeCakeCakeCakeCakeCakeCakeCakeCakeCakeCakeCake I do ...
``` printf('1.cake\n2.cake\n......'); ``` this will be the solution in noloopsare allowed and a singleprintfstatement should do.
Closed.This question does not meetStack Overflow guidelines. It is not currently accepting answers.Questions asking us torecommend or find a tool, library or favorite off-site resourceare off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead,describe the problemand what has been do...
it depends in which language you want to use it. the libcurl is most commen e.g. in C: http://curl.haxx.se
Wikipedia Says: "Each header file contains one or more function declarations, data type definitions, and macros." It says that the header file only contains declaration.So where are the definitions of any particular inbuilt function written? How it is accessed in any C program?
The standard C library functions are provided in libraries along with your compiler and the rest of your toolchain. For unix-like systems, that's usually in libraries calledlibcandlibm.libcis normally linked with your program by default.libmsometimes is and sometimes isn't.
This question already has answers here:What does the "=!" operator do? [closed](6 answers)Closed9 years ago. I was surprised by this code: ``` if (a =! b) { // let it be on false ... } ``` Butais never assigned by a value. What's this operator about?
That's two operators,=and!, not one. It might be an obfuscated way of writing ``` a = !b; if (a) { // whatever } ``` settingato the logical inverse ofb, and testing whether the result is true (or, equivalently, whetherbwas false). Or it might be a mistyping ofa != b.
Could you please help me? I'm a beginner at C and my code doesn't work. I'm trying to determine largest prime factor of 600851475143 and when I run the code, it just does nothing. Trying with smaller number however works. ``` long i; for (i = 600851475143; i > 1; i--) { if (600851475143 % i == 0) { ...
It's probably a 32-bit system. The number600851475143is bigger than 32 bits. Instead oflong itry: ``` long long i; ``` And instead ofprintf("%d\n", i);try: ``` printf("%lld\n", i); ``` And use600851475143LLin place of600851475143.
I want to know how to make Cmake give me a target that will allow me to save the .i files from myCprogram with the macro expansion, etc completed. Will I need to make a custom target to do this?
If your are using the Makefile generator, then there are already targets for .i files. Typemake help, and you will see all the targets, including those suffixed by.i,.s, and.o.
Closed.This question isnot reproducible or was caused by typos. It is not currently accepting answers.This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may beon-topichere, this one was resolved in a way less likely to help future readers.Closed9 years ago.Improve...
You are correct, the code is wrong. Likely, it is a typo, and the intent was either to defineior to use1[arr].
I have to create a very inexpensive algorithm (processor and memory) to remove the firstcharfrom a string (char array) in C. I'm currently using: ``` char *newvalue = strdup(value+1); free(value); value = newvalue; ``` But I want to know if there is some less expensive way to do that. The stringvalueis dynamically ...
value+1is achar*that represent the string with the first character removed. It is the less expensive way to obtain such a string.. You'll have to be careful when freeing memory though to make sure to free the original pointer and not the shifted one.
I want to useg_key_file_get_stringfrom linux glib library to read string between quotes from configuration file and ignore them. Now i'm usingstring_key=valuebut i want to usestring_key="value"in configuration file and when i call:conf->value = g_key_file_get_string(gkf, "GENERAL_CONFIG","string_key", &error); i exp...
Since you are usingglib, you are probably looking forg_shell_unquote().
I have a 2D array for ex ``` int arr[3][3] = {{1,2,3},{4,5,6},{7,8,9}}; ``` Then what would be type of this? ``` &arr[1] ``` I thought it would be**(double pointer) But when I write a function such as ``` int **get_arr() { return &arr[1]; } ``` I get a warning ``` return from incompatible pointer type ```
Then what would be type of this?&arr[1] Type of&arr[1]isint (*)[3], i.e, it is of typepointer to an array of 3 integers. I thought it would be**(double pointer) You thought wrong.&arr[1]is not a double pointer. As I mentioned already that, it is of typeint (*)[3].
I'm having difficulty finding out a specific way to copy a short integer into a char array. Let's say I have: ``` unsigned short xVal = 5; unsigned short yVal = 12; char x[3]; char y[3]; ``` and I want to copy the short integers into the respective char arrays filling the empty digits with 0s: ``` char value outpu...
The simplest would be. ``` unsigned short xVal = 5; unsigned short yVal = 12; char x[5]; char y[5]; sprintf(x,"%04u",xVal); sprintf(y,"%04u",yVal); printf("%s\n",x); printf("%s\n",y); ``` Note that x and y should be declared as char arrays of 5 elements for the null character
I want to create a dump in windows with the functionMiniDumpWriteDump. The problem is that that function takes a Handle to a file to write the result to. I want the data in memory so that I can send it over the internet. Therefore, I was wondering if there is a way to create a handle without a file backing it and I ca...
You can use memory mapped files. See here:http://msdn.microsoft.com/en-us/library/windows/desktop/aa366537(v=vs.85).aspx You need to pass hFile = INVALID_HANDLE_VALUE and specify maximal size of file. Please, check msdn for the details.
This question already has answers here:What does the "=!" operator do? [closed](6 answers)Closed9 years ago. I was surprised by this code: ``` if (a =! b) { // let it be on false ... } ``` Butais never assigned by a value. What's this operator about?
That's two operators,=and!, not one. It might be an obfuscated way of writing ``` a = !b; if (a) { // whatever } ``` settingato the logical inverse ofb, and testing whether the result is true (or, equivalently, whetherbwas false). Or it might be a mistyping ofa != b.
Could you please help me? I'm a beginner at C and my code doesn't work. I'm trying to determine largest prime factor of 600851475143 and when I run the code, it just does nothing. Trying with smaller number however works. ``` long i; for (i = 600851475143; i > 1; i--) { if (600851475143 % i == 0) { ...
It's probably a 32-bit system. The number600851475143is bigger than 32 bits. Instead oflong itry: ``` long long i; ``` And instead ofprintf("%d\n", i);try: ``` printf("%lld\n", i); ``` And use600851475143LLin place of600851475143.
I want to know how to make Cmake give me a target that will allow me to save the .i files from myCprogram with the macro expansion, etc completed. Will I need to make a custom target to do this?
If your are using the Makefile generator, then there are already targets for .i files. Typemake help, and you will see all the targets, including those suffixed by.i,.s, and.o.
Closed. This question needsdetails or clarity. It is not currently accepting answers.Want to improve this question?Add details and clarify the problem byediting this post.Closed9 years ago.Improve this question i have writen code below for getting numbers i want to enter as input but when i try to get them and find a...
You declared your variable length arrayaveat wrong place. Declare it after getting the inputn. And declarenasintinstead ofconst int(otherwise modifying aconstqualified type objects invokesundefined behavior). ``` int n; float max,min; int i,x=0,z=0; printf("How many numbers do you want to enter?\n"); scanf("%d",&n); ...
This question already has answers here:Why does malloc initialize the values to 0 in gcc?(10 answers)Closed9 years ago. Code: ``` cpdef values(int n): cdef size_t i cdef double * v = <double *> malloc(sizeof(double) * n) if v is NULL: abort() for i in range(n): print v[i] ``` Output:...
For all intents and purposes the contents ofmalloc'ed memory block is to be treated as random and undetermined. The values found in the allocated buffer may be contents of memory blocks previously freed.
I am writing my code in C and I have the following situation: ``` typedef struct MyStruct { /** Some comment */ int (*const (*FuncList)[])(void); } MyList; ``` The Doxygen is returning the following error: Warning: documented symbol `int (*const MyStruct::FuncList' was not declared or defined. It seens that t...
I think you should help doxygen (and the readers of your code) by using some typedefs, e.g. ``` /** A function pointer */ typedef int (*TFuncPtr)(void); /** const pointer to an array of TFuncPtr's */ typedef TFuncPtr (*const TFuncList)[]; typedef struct MyStruct { /** Some comment */ TFuncList FuncList; }...
I have code this add_str function : ``` void add_str(char *str1, char *str2, char **res) { int i; int j = 0; res[0] = malloc((strlen(str1) + strlen(str2) + 1) * sizeof(char)); if (res[0] == NULL) return; for (i = 0; str1[i]; i++) res[0][j++] = str1[i]; for (i = 0; str2[i]; i++) res[0][...
resis a pointer to a pointer, so you need to dereference it before you use it. You're right thatres[0]isn't the right way to do that though in this context. Use(*res)instead.
I am trying to define anHTMLstring as a char array, However it's really painful to add the escape chars where they are needed, meaning the I have to escape every"in the string and so on. Inc#you could do something like : ``` string x = @"\a\a\a\"; //@ adds the escape chars where needed ``` is there any way to do it...
This feature (ala c# verbatim string literal) is available starting with C++11. You can use raw string literals like below: ``` const char* s = R"( " " " \n \a )"; cout << s; ``` prints: ``` " " " \n \a ``` a raw string starts withR"(and ends with)"
I'm trying to calculate difference between twotime_t.butdifftimereturns its first parameter instead of the difference!My code is: ``` #include <windows.h> #include <stdio.h> #include <time.h> #include <unistd.h> int main(){ time_t etime_t,now_t; double time_diff; now_t=1388525484L; etime_t=13...
A MinGw bug. They compile difftime to a call of a standard windows function. However, they call a 32 bit version of difftime, even if arguments are 64 bits. This gives the expected result as it substracts higher half of the first argument (which is 0) from its lower half. Seebug reporthere. It can be temporarily fixed...
I am trying to access a column from an excel document from a C code in Linux. Is there a simple way to do this? There are more than 47000 rows and I want to store the data of particular column into an array of data structure.
Use xlsLib library for parsing excel file. You can find more informationhereandHere
Somehow the standard C header files seem to have gone missing. /usr/include/ used to include inttypes.h, sys/types.h, stdlib.h, string.h and a myriad of other standard C files. locate still shows these files present in /usr/include until I ran updatedb. How do I recover these files? I tried re-installing gcc using ...
You must have uninstalled the package that supplied those files. The package might have been uninstalled as it was no longer needed - marked as automatically installed by some other package. Check the package that contains the files onpackages.ubuntu.comand install the package that contains the file. Search result f...
``` #include <stdio.h> main() { char* str; char* strrev; int i = 0; int j = 0; int c; printf("Enter the string\n"); scanf("%[^\n]%*c", str); while (*(str + i) != '\n') { i++; } for (c = i; c >= 0; c--) { *(strrev + j) = *(str + c); j++;...
There are many issues: You never allocate memory forstrorstrrev. This is why it crashes; writing to uninitialized pointers invokes undefined behavior, often resulting in a seg fault.You're usingscanf()with a complex conversion when you could just usefgets().You should usestrlen()rather than looping to find the end of...
Since atask_structis allocated for each thread in Linux, how to I find the threads that belong to the same process? So, that was the general question. To elaborate, I need to write a kernel function that traverses the threads that belong to a process (p), given a pointer to itstask_structor pid, and do something wit...
linux/sched.hhas this function: ``` struct task_struct *next_thread(const struct task_struct *p); ``` And other supporting functions, such asget_nr_threads(). You'll have to iterate like e.g. ``` struct task_struct *t = task; do { /*....*/ t = next_thread(t); } while (t != task); ``` See also code infs/pr...
Closed. This question needs to be morefocused. It is not currently accepting answers.Want to improve this question?Update the question so it focuses on one problem only byediting this post.Closed9 years ago.Improve this question I need to do a program in C/C++ in witch one i'll need to take each sction of a PE File, ...
Download the documentation here: Microsoft PE and COFF Specification Sample code from CodeProject:Parse a PE
The following code prints the maximum and the biggest negative value (if we have -10 and -5, -5 is bigger) of numbers entered unitl a symbol is reached. My question is if there is a better way to find the largest negative value (avoiding INT_MIN or other clumsy ways of this kind). ``` #include <stdio.h> #include <con...
Start bnn at 0.0 Then ``` if ((n < 0) && ((bnn == 0.0) || (n > bnn))) bnn = n; ```
Somehow the standard C header files seem to have gone missing. /usr/include/ used to include inttypes.h, sys/types.h, stdlib.h, string.h and a myriad of other standard C files. locate still shows these files present in /usr/include until I ran updatedb. How do I recover these files? I tried re-installing gcc using ...
You must have uninstalled the package that supplied those files. The package might have been uninstalled as it was no longer needed - marked as automatically installed by some other package. Check the package that contains the files onpackages.ubuntu.comand install the package that contains the file. Search result f...
``` #include <stdio.h> main() { char* str; char* strrev; int i = 0; int j = 0; int c; printf("Enter the string\n"); scanf("%[^\n]%*c", str); while (*(str + i) != '\n') { i++; } for (c = i; c >= 0; c--) { *(strrev + j) = *(str + c); j++;...
There are many issues: You never allocate memory forstrorstrrev. This is why it crashes; writing to uninitialized pointers invokes undefined behavior, often resulting in a seg fault.You're usingscanf()with a complex conversion when you could just usefgets().You should usestrlen()rather than looping to find the end of...
``` #include <stdio.h> struct p { char *name; struct p *next; }; struct p *ptrary[10]; int main() { struct p p, q; p.name = "xyz"; p.next = NULL; ptrary[0] = &p; strcpy(q.name, p.name); ptrary[1] = &q; printf("%s\n", pt...
You will have to allocate some memory before using it. ``` q.name = malloc(10); strcpy(q.name, p.name); ``` Edit: As correctly pointer out by unwind,sizeofcharwill be always 1. Hence removing frommalloc.
I am having following union ``` union data { uint64_t val; struct{ .... } }; ``` and I have a function ``` func(union data mydata[]) { printf("%llu",(uint64_t)mydata[0]); // Here is the error } ``` When i compile this code it is giving following error ``` error: aggregate value used where ...
You are failing to access a field of the indexed union array:mydata[0]is a value of typeunion data, and can't be cast touint64_t. You need to access the proper union member: ``` printf("%" PRIu64, mydata[0].val); ``` to select theuint64_tvalue. No need for the cast. Also: UsePRIu64to portably print 64-bit values, ...
I'm taking a course inCand came across this #define. Reading up on it, it is that you define something. Example: ``` #define FAMILY 4 ``` Then every time I set something equal to family or call family it is the value 4. But I also came across this: ``` #define EVER ;; #define FAMILY 4 ``` What does it mean if afte...
EVER will be equivalent to exactly this: ``` ;; ``` This means that you could have: ``` #define EVER ;; //..... for(EVER){printf("This will print forever");} ``` which will be equivalent to: ``` for(;;){printf("This will print forever");} ``` You should however exercise caution when using aliases for such str...
Closed.This question does not meetStack Overflow guidelines. It is not currently accepting answers.Questions asking for code mustdemonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and theexpectedresults. See also:Stack Overflow question checklistClosed9 ...
It will return either1or0depending upon the conditionret < 0istrueorfalse. You can understand this as ``` if(ret < 0) return 1; else return 0; ```
I am asked to convert a python program to a C program.The Python program includes the loop statement which i am unable to convert. ``` for line in sys.stdin: <Some Code> ``` I am looking for its substitution in C.I thought the following code might work but I doubt it. ``` char A[100] while(1) A=gets(); ``` Try...
I second Joachim's response: ``` char A[100]; /* Your code misses the semicolon here. */ while(fgets(A, sizeof A, stdin) != NULL) { /* process A here */ } ``` do note that this is limited to a line length of 100 characters, the Python code is not limited in that way. If you have it, usegetline()instead, it has n...
I wrote the following code, but it gets stuck into an infinite loop. Can somebody help me out at this topic? ``` #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<string.h> void main() { FILE *fp; char s[10]; fp=fopen("text1.txt", "w"); if(fp==NULL) { printf("Error openin...
This program will run, as expected, until the input signals "end of file". If you're not using input redirection (e.g. running it asmyprogram < somefile.txt) but instead running with the console (keyboard) as the input device, you must manually signal end of file to cause the loop to end. In Linux, this is done by p...
Following code is throwing "warning: pointer/integer type mismatch in conditional expression". How could I solve this? ``` #include<stdio.h> int main() { char *str = "Error"; char *sch_str="pqrs"; int i=1; if (i >= 0) str = (sch_str[i] != NULL) ? sch_str[i] : "Unknown"; printf("%...
1.sch_str[i]is not a pointer. Cannot compare it withNULL.2.Cannot put [assign the value of]sch_str[i]intostr
This question already has answers here:Stack smashing detected(10 answers)Closed9 years ago. I made this little program to count how many 'en's there are in a string. It does work, but I get an error saying there's stack smashing detected. I do not understand how to solve this... Can anyone give me a tip? ``` #inclu...
Never usegets(), it's vulnerable to buffer overflow. Use the much safer alternativefgets(), like so: ``` char buf[256]; if(fgets(buf, sizeof buf, stdin) != NULL) { /* process string here */ } ```
``` #include<stdio.h> void main(){ int i; i = i-3; printf("%d",i); // output -3 } ``` Why answer is 3 every time run this c program. but we knows c picks random value for variable which is not initialized. so why it gives -3. I also try it using auto storage class. I am using codeblocks compiler.
Your code is causing undefined behavior. Anything could happen in the code. Your code might print 3 or 300 or a Mona Lisa picture on the screen. 6.3.2.1p2: If the lvalue designates an object of automatic storage duration that could have been declared with the register storage class (never had its address taken), and...
Lately I have been studying C and I came across the concept of Union. I like it because it can be used to represent any data type. Of course it is helpful only for certain rare and special circumstances. In C++ everything is done with classes. Of course similar functionality like Union can be implemented using classes...
You probably wantBoost.Variant. C++ does haveunionlike in C, but because auniondoesn't keep track of what type is stored in it, it wouldn't be able to execute the correct destructor if used with non-trivial types. The resulting restrictions on the use ofunionin C++ make it quite non-general.
I have some difficulty to cross-compile a simple HelloWorld in C. The host is Ubuntu X86_64 and the target is ARMv6-compatible processor rev 7 (v6l) running Linux kernel 2.6.21.7 If i try: ``` arm-linux-gnueabi-gcc -static -march=armv6 hello.c -o hello ``` I get a segmentation fault on the target. File command outp...
It worked with sourcery:https://sourcery.mentor.com/sgpp/lite/arm/portal/release2029 After the installation, I had to reboot my computer then it compiled fine with this command: ``` arm-none-linux-gnueabi-gcc -o hello -static hello.c ```
I am asked to convert a python program to a C program.The Python program includes the loop statement which i am unable to convert. ``` for line in sys.stdin: <Some Code> ``` I am looking for its substitution in C.I thought the following code might work but I doubt it. ``` char A[100] while(1) A=gets(); ``` Try...
I second Joachim's response: ``` char A[100]; /* Your code misses the semicolon here. */ while(fgets(A, sizeof A, stdin) != NULL) { /* process A here */ } ``` do note that this is limited to a line length of 100 characters, the Python code is not limited in that way. If you have it, usegetline()instead, it has n...
I wrote the following code, but it gets stuck into an infinite loop. Can somebody help me out at this topic? ``` #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<string.h> void main() { FILE *fp; char s[10]; fp=fopen("text1.txt", "w"); if(fp==NULL) { printf("Error openin...
This program will run, as expected, until the input signals "end of file". If you're not using input redirection (e.g. running it asmyprogram < somefile.txt) but instead running with the console (keyboard) as the input device, you must manually signal end of file to cause the loop to end. In Linux, this is done by p...
Following code is throwing "warning: pointer/integer type mismatch in conditional expression". How could I solve this? ``` #include<stdio.h> int main() { char *str = "Error"; char *sch_str="pqrs"; int i=1; if (i >= 0) str = (sch_str[i] != NULL) ? sch_str[i] : "Unknown"; printf("%...
1.sch_str[i]is not a pointer. Cannot compare it withNULL.2.Cannot put [assign the value of]sch_str[i]intostr
This question already has answers here:Stack smashing detected(10 answers)Closed9 years ago. I made this little program to count how many 'en's there are in a string. It does work, but I get an error saying there's stack smashing detected. I do not understand how to solve this... Can anyone give me a tip? ``` #inclu...
Never usegets(), it's vulnerable to buffer overflow. Use the much safer alternativefgets(), like so: ``` char buf[256]; if(fgets(buf, sizeof buf, stdin) != NULL) { /* process string here */ } ```
In Xcode 4.0, by default, the indentation is like below: ``` #ifdef SYNTHETIC char buff_inarray[100]; #else char buff_in; #endif ``` However, I want it to be the simpler version, like: ``` #ifdef SYNTHETIC char buff_inarray[100]; #else char buff_in; #endif ``` How to set it?
You can't modify Xcode indentation settings. You'll have to either use a different editor and re-indent all code yourself. Maximum you can do, is disable autoindent. It is done in Xcode's preferences → Text Editing → Indentation. This pic is from Xcode 5, but I'm pretty sure version 4 had it there as well. Also, i...
I am a newbie in C. I know this is correct: ``` char* Str; Str = (char*)calloc(Str_Len, sizeof(char)); ``` , but why this is not correct? ``` char* Str; *Str = (char*)calloc(Str_Len, sizeof(char)); ``` How to modify it? Thanks.
First is legal, butdo not cast the return value ofmallocorcallocin C (as their return type isvoid *).In second caseStrischartype, you can't allocate memory more thatn1byte to it. Alsocallocreturnspointerbut*Stris of typechar. You can't assign achar *data type tochartype.
I want the absolute-value from a negative double - and I thought theabs-function was as easy to use as in java - but NOT! It seems that theabs-function returns an int because I have the value 3.8951 and the output is 3.000000 ``` double d1 = abs(-3.8951); printf("d1: ...%lf", d1); ``` How can I fix this problem? Th...
Usefabs()(inmath.h) to get absolute-value fordouble: ``` double d1 = fabs(-3.8951); ```
I am using Net-snmp. I want to send traps in my subnet. I am having IP of my m/c as 10.0.2.15. I want to send it in 10.0.2.0/24 subnet. I have tried command as follows snmptrap -v 2c -c public 10.0.2.0/24 "" OID-value pairs It was getting hanged and resulting into following error getaddrinfo: 10.0.2.0/24 Temporary f...
I think sending traps in subnet is not possible. Sending trap to particular destination having IP is allowed.
I am a newbie in C. I know this is correct: ``` char* Str; Str = (char*)calloc(Str_Len, sizeof(char)); ``` , but why this is not correct? ``` char* Str; *Str = (char*)calloc(Str_Len, sizeof(char)); ``` How to modify it? Thanks.
First is legal, butdo not cast the return value ofmallocorcallocin C (as their return type isvoid *).In second caseStrischartype, you can't allocate memory more thatn1byte to it. Alsocallocreturnspointerbut*Stris of typechar. You can't assign achar *data type tochartype.
I want the absolute-value from a negative double - and I thought theabs-function was as easy to use as in java - but NOT! It seems that theabs-function returns an int because I have the value 3.8951 and the output is 3.000000 ``` double d1 = abs(-3.8951); printf("d1: ...%lf", d1); ``` How can I fix this problem? Th...
Usefabs()(inmath.h) to get absolute-value fordouble: ``` double d1 = fabs(-3.8951); ```
I am using Net-snmp. I want to send traps in my subnet. I am having IP of my m/c as 10.0.2.15. I want to send it in 10.0.2.0/24 subnet. I have tried command as follows snmptrap -v 2c -c public 10.0.2.0/24 "" OID-value pairs It was getting hanged and resulting into following error getaddrinfo: 10.0.2.0/24 Temporary f...
I think sending traps in subnet is not possible. Sending trap to particular destination having IP is allowed.
``` #include<stdio.h> #define TOTAL_NO (sizeof(array) / sizeof(array[0])) int array[]={23,34,12,17,204,99,16}; int main() { int d; for(d=-1; d<=(TOTAL_NO-2); d++) printf("%d\n",array[d+1]); return 0; } ``` Why is this program not displaying contents of array? Where is the bug?
TOTAL_NOreturns a value with typesize_t. This is unsigned sodgets converted to unsigned for the testd<=(TOTAL_NO-2)in the loop exit condition. Assuming 32-bit integers, this makes the initial test ``` 0xffffffff <= 7 ``` This obviously fails, preventing the loop from running. The loop runs as you expect if you ch...
``` auto int a=5; #include<stdio.h> int main () { printf("%d",a); return 0; } ``` I have read that the scope of automatic variables is within the specified block . In the above program, since the auto variable 'a' is declared outside main function, it should be assigned global scope and be accesible within th...
Variables at top-level cannot beauto. They should be either declaredstatic,extern(definition elsewhere) or global (no keyword for that). This won't compile. ``` $ echo "auto int c;" > test.c $ gcc -Wall -c test.c test.c:1:10: error: file-scope declaration of ‘a’ specifies ‘auto’ ```
Program 1: ``` #include<stdio.h> void main() { int i=55; printf("%d %d %d %d\n",i==55,i=40,i==40,i>=10); } ``` Program 2: ``` #include<stdio.h> void main(){ int i = 55; if(i == 55) { printf("hi"); } } ``` First program give output0 40 0 1here in theprintf i == 55and output is 0 and in t...
In the first example, the operators are evaluated in reverse order because they are pushed like this on the stack. The evaluation order is implementation specific and not defined by the C standard. So the squence is like this: i=55 initial assignmenti>=10 == true 1i==40 == false (It's 55) 0i=40 assign...
This question already has answers here:How to load program reading stdin and taking parameters in gdb?(6 answers)How do I pass a command line argument while starting up GDB in Linux? [duplicate](4 answers)Closed9 years ago. often i see some gdb guide using examples without parameters. But in parctice, i need to gdb d...
You may want to take a look at therunandstartcommands of gdb—you can pass them the commandline parameters just like you are used to at the shell prompt: ``` % gdb my_program [...] start par1 par2 par3 ... ```
When calling JNI functions from Java in an Android app using JNI, is their a guaranteed lifetime for variables declared at file-scope? We call this function a few times, can the Android system unload our program from memory without terminating the app's process in order to conserve memory in between calls? Is our vari...
Any operating system can swap or page memory, but I don't see why it concerns you. The 'guaranteed life' of a file-scoped variable in C is the life of the process.
I am sitting in a Web Development Workshop and the guy just told that there is a Triple Equal To Operator===in C along with others as well. (The Only Language I have read till now). Just tried this code in Visual Studio 2013 and the compiler is giving me errors that there is a syntax error where I typed the===. Here ...
No.=is used for assignment and==is used for equality. There is no===operator in C.
When I use ``` fstat(fileno(file), &st); //struct stat st buf = malloc(fsize); //size_t fsize fread(buf, 1, fsize, file); ``` I'm really in doubt, becausemallocshould alloc likefsize * sizeof(size_t)large space for me, but when I tried to visit likebuf + 8*fsize, and I'm out of bounds. though, thebuf+fsizei...
Your code saysmalloc(fsize)but what you want ismalloc(fsize * sizeof(size_t)). Themallocfunction takes the number of bytes to allocate. It has no way to know that you are going to use the memory to storesize_t's. Update: I may have misunderstood the question. I'll update this answer when the questioner answers the qu...
Please can anyone help me figure this out, i have SQL query in C program i want to use LIKE '%STR%' in the query but STR is a variable therefore, i want to usesqlite3_mprintf()to parse it; ``` const char *STR = "eng"; q = "SELECT * FROM country where Name LIKE '%%q%';"; q = sqlite3_mprintf(q, STR); ``` How can i mat...
Ifsqlite3_mprintfreally behaves likesnprintfas documented, something like: ``` q = sqlite3_mprintf("SELECT * FROM country where Name LIKE '%%%q%%';", STR); ``` should work.
I was looking through the source code of the PHP interpreter and found this piece of code : Why is there a static char * variable defined but not used?I'm sure there has to be a reason for that, but with the data I have, I don't get it :-/ https://github.com/php/php-src/blob/master/main/strlcat.c It seems to be the...
From wikipedia (Source Code Control System) SCCS is also known for the sccsid string, for example:static char sccsid[] = "@(#)ls.c 8.1 (Berkeley) 6/11/93";This string contains the file name, date, and can also contain a comment. After compilation, this string can be found in binary and object files by looking ...
I cannot figure out how to get the number of MPI processes that need to be ran from the file. I have a MakeFile and in my 'run' goal I have: ``` mpirun --hostfile ${HOSTFILE} ./${PROGRAM} $(input_file) ``` That's working fine but I want to specify the number of processes that need to be ran and I want to get them fr...
Excluding comments and whitespace, there's one host per line. You could strip all that other stuff and just count the number of lines. If you generate the hostfile yourself and you know it's 'clean' thenwc -l ${HOSTFILE}should do it.
i'm not even sure if comma operator is the problem here but i didn't want to write "Weird problem with my C code. ``` #include <stdio.h> int main() { int i = 0, x = 0, y = 0, z = 0; y = 3; z = 5; (x&&(y = z), i = 10); printf("i:%d, x:%d, y:%d, z:%d\n", x, y, z, i); return 0; } ``` Compil...
``` printf("i:%d, x:%d, y:%d, z:%d\n", x, y, z, i); ``` You printedxasi,yasx,zasyandiasz.
I am sitting in a Web Development Workshop and the guy just told that there is a Triple Equal To Operator===in C along with others as well. (The Only Language I have read till now). Just tried this code in Visual Studio 2013 and the compiler is giving me errors that there is a syntax error where I typed the===. Here ...
No.=is used for assignment and==is used for equality. There is no===operator in C.
When I use ``` fstat(fileno(file), &st); //struct stat st buf = malloc(fsize); //size_t fsize fread(buf, 1, fsize, file); ``` I'm really in doubt, becausemallocshould alloc likefsize * sizeof(size_t)large space for me, but when I tried to visit likebuf + 8*fsize, and I'm out of bounds. though, thebuf+fsizei...
Your code saysmalloc(fsize)but what you want ismalloc(fsize * sizeof(size_t)). Themallocfunction takes the number of bytes to allocate. It has no way to know that you are going to use the memory to storesize_t's. Update: I may have misunderstood the question. I'll update this answer when the questioner answers the qu...
Please can anyone help me figure this out, i have SQL query in C program i want to use LIKE '%STR%' in the query but STR is a variable therefore, i want to usesqlite3_mprintf()to parse it; ``` const char *STR = "eng"; q = "SELECT * FROM country where Name LIKE '%%q%';"; q = sqlite3_mprintf(q, STR); ``` How can i mat...
Ifsqlite3_mprintfreally behaves likesnprintfas documented, something like: ``` q = sqlite3_mprintf("SELECT * FROM country where Name LIKE '%%%q%%';", STR); ``` should work.
I was looking through the source code of the PHP interpreter and found this piece of code : Why is there a static char * variable defined but not used?I'm sure there has to be a reason for that, but with the data I have, I don't get it :-/ https://github.com/php/php-src/blob/master/main/strlcat.c It seems to be the...
From wikipedia (Source Code Control System) SCCS is also known for the sccsid string, for example:static char sccsid[] = "@(#)ls.c 8.1 (Berkeley) 6/11/93";This string contains the file name, date, and can also contain a comment. After compilation, this string can be found in binary and object files by looking ...
I cannot figure out how to get the number of MPI processes that need to be ran from the file. I have a MakeFile and in my 'run' goal I have: ``` mpirun --hostfile ${HOSTFILE} ./${PROGRAM} $(input_file) ``` That's working fine but I want to specify the number of processes that need to be ran and I want to get them fr...
Excluding comments and whitespace, there's one host per line. You could strip all that other stuff and just count the number of lines. If you generate the hostfile yourself and you know it's 'clean' thenwc -l ${HOSTFILE}should do it.
i'm not even sure if comma operator is the problem here but i didn't want to write "Weird problem with my C code. ``` #include <stdio.h> int main() { int i = 0, x = 0, y = 0, z = 0; y = 3; z = 5; (x&&(y = z), i = 10); printf("i:%d, x:%d, y:%d, z:%d\n", x, y, z, i); return 0; } ``` Compil...
``` printf("i:%d, x:%d, y:%d, z:%d\n", x, y, z, i); ``` You printedxasi,yasx,zasyandiasz.
Is it possible, under some circumstance, in ANSI-C, to start arrays in index 1 instead of 0? (some compiler options which stays under the definition of ANSI-C, not MACROS or such) e.g ``` int arr[2]; arr[2] = 5; arr[1] = 4; ``` will be valid code which will behave properly.
No. There is no such thing in ANSI C.
Recently, I developed a simple file system kernel module. So, I needed to assign my own ioctl function (.unlocked_ioctl) to thefile_operationstructure to implement specific commands to my file system module. The Ext4 file system has its own ioctl function, for example. Then, I created a file using theddcommand and mo...
If you open/dev/loop0, you're accessing a loop device, and therefore you're talking to the loop driver. The ioctl handler that you've registered for your filesystem applies to files opened on a mounted filesystem. ``` fd = open("/mnt/something", O_RDWR); ioctl(fd, MY_COMMAND_1, &my_struct_t); ```
I write a code to classify color in an image. I compile the code without problem. But when i try to execute it it show me this error. ``` OpenCV Error: Assertion failed (dst.data == dst0.data) in cvCvtColor, file /build/buildd/opencv-2.3.1/modules/imgproc/src/color.cpp, line 3175 terminate called after throwing an in...
It is maybe the pointer problem. Thispostmay help you. Pay attention to the object definition, and the usage ofcvCvtColor
``` struct people { char *name; char *surname; } *human; human = malloc(10*sizeof(struct people)); ``` Hello everyone. I am trying to acccess elements of this struct array but I think I am doing it wrong.I tried this to access second element's name stringhuman[1].name;And when it didn't worked I tried thishum...
declare the struct and the array that wiill be simpler ``` typedef struct people { char *name; char *surname; } people; people * human=malloc(10*sizeof(struct people)); humam[0].name=malloc((10+1)*sizeof(char)); strcpy(human[0].name,"John"); ``` Don't forget to use malloc for the surname and name because...
Is it possible to call a function in a C++ DLL from C code? The function is not declaredextern "C". An ugly platform dependent hack that only works with Visual Studio is fine. Calling conventions should not be a major issue, but how do I deal with name mangling.? For instance with Visual Studio, a C++ function with s...
Wrap the offenging function in another C++ function, and declare it withextern "C". No need to create a special DLL for it, just include one C++ file in your project.
I seem to be having a problem how the following code generates output: ``` main() { int k = 35 ; printf ( "\n%d %d %d", k == 35, k = 50, k > 40 ) ; } ``` Sincekis initialized to 35, then the first relationk==35must evaluate to true, hence a non-zero value, also for the third condition, as the value ofkhas b...
The function arguments can be evaluated in any order. Your compiler has chosen to evaluate the arguments from right to left, i.e. ``` main() { int k = 35 ; int result_first = (k > 40); // 0 int result_second = (k = 50); // 50 int result_third = (k == 35); // 0 printf ( "\n%d %d %d", result_third...
While looking through puzzles and answers in the code golf Q&A section, I came acrossthis solutionfor the longest and most obscure ways to return 1 Quoting from the answer, ``` int foo(void) { return! 0; } int bar(void) { int i=7; while (i --> 0); return-i; } ``` The --> 'operator' is already well-...
It's really the same idea as with-->. C compilerstokenizeprogram text using aparticular algorithmthat makes ``` return-i ``` parse like ``` return -i ``` and ``` return! 0 ``` parse like ``` return !0 ``` All the same.
This question already has answers here:Why is initializing an integer in C++ to 010 different from initializing it to 10?(4 answers)Closed9 years ago. ``` #include<stdio.h> void main(){ int i; i = 011; printf("%d",i); } ``` This program gives output as 9. I don't know the reason for that. Please help me to fig...
In C, you can represent the value 9 by: Hexadecimal (Base 16):0x9Decimal (Base 10):9Octal (Base 8):011
How can I castvoid*toint ( * () ) (int,...)? Thevoid*is coming from adlsym. This code isn't compiling: ``` typedef int ( *PSYS () ) (int,...); PSYS getf = (PSYS) dlsym(lib, "function" ); ```
PSYS is the type of a function, not a pointer to a function. You want ``` typedef int ( *PSYS () ) (int,...); PSYS* getf = (PSYS*) dlsym(lib, "function" ); ```
Im trying to pass a 3 Dimensional array to a function. I got this decleration of the array ``` char cube[N][N][N]; ``` It's size (N) is a constant.I want to pass it to a function so I can work on the array in the function and change it without copying the entire array each call.. I actually want to pass a pointer t...
Well, the simplest is to just declare the parameter aschar cube[N][N][N];orchar cube[][N][N];in your function, and the array will be passed by pointer (yes, it's counter-intuitive, but it really is how it works.
I am working with C and C++ for some time. While learning the basics you can bump intosuch interesting thing asbit fields. Usage of bit fields in programming practice has somehow controversial character. In which kind of situations this low-level feature usage provides a real benefit, and are there concrete examples...
When working with embedded systems and microcontrollers, individual bits in a register may be associated with a processor setting or input/output. Using bit fields allows these individual bits to be worked with by name instead of doing bitwise operations on the entire register. It's mostly an aesthetic feature but c...
is there a way for a C program on a linux server to count total number of tcp sockets with non-empty SNDBUF, that is non-empty pipe, or in other words, when data transfer is in progress. Obviously this would have to be counted at an "instance"... Good approximation of such number would be fine. Thanks.
The/proc/net/tcpfile contains a list of all open TCP sockets, and shows the send and receive queues. Finding official documentation on the format of this fileis somewhat tricky, but luckily it's somewhat self-explanatory.
I am working with Code::Blocks and trying to program with the C language. I have created a header file, an implementation file and the main. When I compile, I have no errors, but when I run it I get the following error. You must select a host application to "run" a library... The libraries are all in the same folder...
Seems like you have createddll. Change to executable. You may find details how to fix it/ ``` Properties -> Build Target -> 'Type' -> Console application ``` https://stackoverflow.com/a/8506935/2648826
I have very simple code that should run on background and at 1 am shut down the computer: ``` #include <ctime> #include <cstdlib> #include <unistd.h> int main() { time_t t;struct tm * now; daemon(0,0); while(1){ t = time(0); now = localtime( & t ); if(now->tm_hour==1){ ...
If you are writing C code, don't use C++ headers (ctime,cstdlib). Replace those#includes with#include <stdlib.h>and#include <time.h>. If the behavior of this code is really as you describe (which I would find surprising), then this is probably the source of the error.
i need to run a ping to HOST though IP i found the syntax is ping -S IP HOST how can i achieve this programmatic in a c++ program? and get the return exit code of this command? i tried ``` char command[255]; sprintf(command, "ping -S %s %s", ip, host); system(command); ``` but the return value is of the system fun...
On Windows, instead use IcmpSendEcho2 to implement the ping functionality. Check this linkhttp://msdn.microsoft.com/en-us/library/aa366051%28VS.85%29.aspx
i have project in C language, but if i start check valgrind, i have error ``` Conditional jump or move depends on uninitialised value(s) at 0x804B2C3: nameOfMethodC (in ...ap.exe) by 0x804A62E: nameOfMethodB (in ...ap.exe) by 0x80493A2: nameOfMethodA (in ...ap.exe) ``` How can i find this uninitialized variable? Is...
Make sureap.exeis compiled with debugging information enabled and optimizations disabled.
Now can I copy 4 bytes (known start position, NOT 0) in an array (char*data) to aDWORD? There are two parts to this: first, getting the 4 bytes from the array at the specified position (4 elements, each element is a char which is 1 byte in C), and then moving them to a DWORD. I'm not sure how to do either. Thanks!
You can usememcpy(it requiresstring.hheader): ``` #include <stdio.h> #include <string.h> #include <inttypes.h> int main(void) { uint8_t array[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 } uint32_t dword; size_t offset = 2; memcpy(&dword, array + offset, sizeof(dword)...
I am learning C. I came across the following program - ``` #include <stdio.h> int main() { int var1 = 2, var2 = 6; var2 = var2 || var1++ && printf("Computer World"); printf("%d %d\n", var1, var2); return 0; } ``` After compilation with gcc 4.4.5 on Ubuntu 10.10, I'm getting the output as - ``` 2 1 ``` I u...
``` var2 || var1++ && printf("Computer World"); ``` is a logic operation so if thevar2istrue(var2 is not equal to zero) then the second logic operationvar1++ && printf("Computer World");will not be executed (It's called ashort-circuit operation) . So that's why thevar1is not incremented Try to inverse your logic ope...
Closed.This question does not meetStack Overflow guidelines. It is not currently accepting answers.Questions asking for code mustdemonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and theexpectedresults. See also:Stack Overflow question checklistClosed9 ...
By allocating some memory before using it. ``` char *a; a=malloc(sizeof(char)*10); scanf("%s",a); printf("%s",a); return 0; ```
I would like to know what does this expression test: ``` if ((a=b)!=0) ``` Is it equivalent to(if (a!=0))?
When used as an operator,=both assigns the value from the right side to the variable on the left side and returns the new value of that variable (for example, ifais an integer value,(a=3.4)returns 3). So this is equivalent to: ``` a=b; if(a!=0) ```
I have write simple program as follows. ``` #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> char* alphabate[]={ (char *)"xyz", (char *)"abc", (char *)"pqr", NULL }; void main() { char **pp; for( pp=alphabate; *pp; pp++ ) { printf("\n alphabate member %s" *...
printf("\n alphabate member %s" *pp); you are missing a comma before *pp
Following is the PROCESS_MEMORY_COUNTERS structure ``` typedef struct _PROCESS_MEMORY_COUNTERS { DWORD cb; DWORD PageFaultCount; SIZE_T PeakWorkingSetSize; SIZE_T WorkingSetSize; SIZE_T QuotaPeakPagedPoolUsage; SIZE_T QuotaPagedPoolUsage; SIZE_T QuotaPeakNonPagedPoolUsage; SIZE_T QuotaNonPagedPoolUs...
The structure member ``` WorkingSetSize ``` gives the current used memory. The working set is the amount of memory physically mapped to the process context at a given time. Ref.:Process Memory Usage Information.
I'm not sure what I am doing wrong here, I am following a tutorial online(thenewboston) and I am getting an error that says "w used as the name of the previous parameter rather than as part of the selector." ``` -(void)setWH: (int) w:(int) height; ```
You're missing part of the selector name: ``` - (void)setWidth:(int)width height:(int)height; // ^--- You're missing this. ```
I'm new to C and need your help. I'm trying to get an integer from a string that has a number in it. I have with me a code I did but the only problem is when I'm assigning years as int i think I'm getting some sort of an address. Is there a way to get my char years into an in years? ``` #include <stdio.h> #include <...
``` int iYear = 0; sscanf(year,"%d",&iYear); ``` This should be the simplest. You might also want to look atatoifunction.
I write code: ``` #include <stdio.h> #include <stdlib.h> #include <string.h> int main(){ char * var=(char*) calloc(10, sizeof(char)); strncpy(var,"123456789",9); strncpy(var, "abcdefghi",1000000 ); printf("This is var == %s\n",var); } ``` but after compiling and running him I haveSe...
strncpyalways pads up to the end of the buffer, so this line: ``` strncpy(var, "abcdefghi",1000000 ); ``` causes the segfault. As you can readhereThe remainder of the buffer is filled with\0.
This question already has answers here:C command-line password input(7 answers)Closed9 years ago. is it possible to do an invisible input like the password prompt under linux when entering the password? I mean, when I use scanf that the chars just don't show up? Or at least are empty spaces? So that the user doesn't...
Thanks for your suggestions. There really was an answer which helped me. Finally I've done it like that: ``` void inputPassword(){ char pass[20]; printf("Password: "); int i = 0; while ((pass[i] = getch()) != '\n' && pass[i] != '\r' && i < 19){ putchar(' '); i++; } pass[i] = '\0'; } ```
I have a string that includes two names and a comma how can i take them apart nd write them to seperate strings.Example ``` char *line="John Smith,Jane Smith"; ``` I am thinking of using sscanf function. ``` sscanf(line,"%s,%s",str1,str2); ``` What should i do?note: I can change comma to space character.
I am thinking of using sscanf function. Don't even think about it. ``` char line[] = "John Smith,Jane Smith"; char *comma = strchr(line, ','); *comma = 0; char *firstName = line; char *secondName = comma + 1; ```
Closed.This question does not meetStack Overflow guidelines. It is not currently accepting answers.Questions asking for code mustdemonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and theexpectedresults. See also:Stack Overflow question checklistClosed9 ...
You would usually usestrtokfor this (strtok_rif you use threads or may have otherwise overlapping parsing sequences).
Please, correct me if I'm wrong. In pseudo code bellow I create space forj. Of couse at the end I need to free space. But ifjwas reaasigned to another variable it is not good to free variablesanotherJobspoace and I will have memory leak ofjanyway, because code is freeinganotherJob. I'm right? ``` j=malloc(sizeof(stru...
Yes, you are correct. Unless you've saved the original value ofjaway somewhere else, it will get leaked. You don't likely want to freeanotherJobhere since you don't know where it came from or if it's going to be free'd somewhere else.