question stringlengths 25 894 | answer stringlengths 4 863 |
|---|---|
I downloaded clutter from LFS (Ver 1.12.2) and tried running the example from Netbeans .
I have included libclutter in the project but i am getting following error :
undefined symbol: clutter_actor_set_pivot_point
Any suggestions or experience ?
|
Problem was something weird ... Finally found Might be useful for somebody later
Mint already had some files in /usr/lib/i386-linux-gnu for libclutter .. Netbeans was reading from there .. a quick readelf showed clutter_actor_set_pivot_point is not there ..
But after fresh installation of libclutter1.12.2 files went... |
I am creating a .so file with a C code. I need to link some other .so files to the .so file am creating. how to do it?
I tried this-L{path to file containing library} -l${library name}is it right?
|
If your library file is called/path/to/libfile.so, then typically you'd need to specify the following arguments to the linker:
```
-L/path/to -lfile
```
Note that we only include the directory in-L, and omit both thelibprefix and the.sosuffix from-l.
|
In Visual C 2010 how do you do a string comparison to check for equality between a char* and a LPWSTR? For example, do something to the extent of
```
LPWSTR *str;
if (*str == "fileName") //...
```
|
I believe the wsccmp function should do what you are looking to do.
http://msdn.microsoft.com/en-us/library/e0z9k731(v=vs.80).aspx
|
```
for(int y = 0; y < 5; y++)
{
char cst1[2] = {info[x+2], info[x+3]};
char cst2[2] = {info[x+5], info[x+6]};
sales[count][atoi(&info[x]) - 1] = atoi(cst1) + atoi(cst2);
x += 8;
}
```
Every time i do the following code the atoi(cst1) value is multiplied by two then added and atoi(cst2) is multiplied b... |
cst1andcst2don't appear to be NUL-terminated.
```
char cst1[] = {info[x+2], info[x+3], '\0'};
char cst2[] = {info[x+5], info[x+6], '\0'};
```
|
How do I launch a new non-interactive shell process from C?
Currently I have the following:
```
system(cmdStr);
//system("/bin/sh -c");
```
The cmdStr is the command I want to execute. I have the reference below to the shell process... but how do I append the cmdStr to it? How do I make it launch a new process?
|
If you don't want to concatenate the string, you can do:
```
if (fork())
{
execl("/bin/sh", "sh", "-c", cmdStr, (char *) NULL);
exit(EXIT_FAILURE);
}
```
which is whatsystembasically does.
Otherwise to a concatenate a string, you should have a look to standard functionsstrcatandstrncatfromstring.h.
|
main
```
...
char coords;
get_coords(1, &coords);
printf("{%s}", coords);
...
```
get_coords:
```
void get_coords(int num, char *coords){
if (num == 1){
*coords = '0-0';
}
}
```
problem seems to happen when the code tries to execute the printf and simply returns ... |
```
char coords;
printf("{%s}", coords);
```
coordsis acharand not a string.%sconversion specification requires achar *argument and not achar. Passing an object of typecharis undefined behavior.
|
I am learning C and wish to write the program using a text editor on my Mac (runningOS X v10.7(Lion)).
I write the.cfile, and compile it usinggcc filename.c- which creates executable file calleda.out. However, when I typea.outor/a.out, I get the following messages:
-bash: a.out: command not foundor-bash: /a.out:No s... |
You need to add a dot to indicate that the executable is in the current directory, as the current directory is not in the path:
```
./a.out
```
|
Say I have 16 64-bit unsigned integers. I have been careful to feed the carry as appropriate between them when performing operations. Could I feed them into a method to convert all of them into a single string of decimal digits, as though it was one 1024-bit binary number? In other words, is it possible to make a meth... |
You could use thedouble dabble algorithm, which circumvents the need for multi-precision multiplication and division. In fact, the Wikipedia page contains a C implementation for this algorithm.
|
When I usedprintf("%.6g\n",36.666666662);, i expected the output36.666667. But the actual output is36.6667
What is wrong with the format I have given? My aim is to have 6 decimal digits
|
This is correct behaviour. According tocplusplus.com:
For a, A, e, E, f and F specifiers: this is the number of digits to be printedafterthe decimal point.For g and G specifiers: This is the maximum number of significant digits to be printed.
If you usefinstead ofgthen it will work as you expected.
Example code
... |
I'm sure it doesn't, but maybe there's black magic in it, so here's my question:
If I have a struct like this:
```
struct mystr {
char * strp,
unsigned int foo,
};
```
and I allocate memory for it and want to release it later. Do I have to do
```
free(mystr_var->strp);
free(mystr_var);
```
or is the last ... |
No, free doesn't follow pointers, you need both lines.
I usually write a function like:
```
void freemystr(mystr *mystr_var)
{
if (mystr_var)
{
free(mystr_var->strp);
mystr_var->strp = NULL;
free(mystr_var);
}
}
```
|
I ran into a problem, I want to add item to the end of the linked list, but it seems that i am getting sucked in an infinite loop here.
```
void addCheckPoint(struct checkPoints **checkPoint) {
struct checkPoints *checkPt = *checkPoint;
while (checkPt->next != NULL) {
checkPt->next;
if (check... |
You never update the value ofcheckPtin your loop. Change the line
```
checkPt->next;
```
to
```
checkPt = checkPt->next;
```
to fix this.
Note that there may be further problems with the function. Despite its name, it doesn't actually add anything to the list. It edits the contents of the tail item instead. I... |
```
#include "stdio.h"
#include "conio.h"
int main()
{
char str1[]=asc(20);
char str2[]="SpApp|";
strcat(str1,str2);
printf(str1);
getch();
}
```
I want to write a program which convertinttoASCIIcode first and then it concatenate withSpApp|and prints the values incprogram.
Althoughprintf("%c"... |
Usesnprintf()to create a buffer containing a string with an appendedint:
```
char str2[32];
snprintf(str2, sizeof(str2), "SpApp|%d", 20);
```
|
I want to copy the screen buffer of the command/powershell window to a text file using C/C++/Powershell.
Is there any way to do it?
|
Use the Host console API:-
```
$rec = new-object System.Management.Automation.Host.Rectangle 0,0,($host.ui.rawui.BufferSize.Width - 1),$host.ui.rawui.CursorPosition.Y
$buffer = $host.ui.rawui.GetBufferContents($rec)
```
Write buffer to file using >> or |
|
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened,visit the help center.Closed10 years ago.
I would like to include a file name... |
You can embed a EXE in a resource, extract and execute it. Keep in mind that an EXE may have dependent DLLs.
Embedding an external executable inside a C# program
However, I would suggest you look at the7Zip DLLinstead (also available from 7-zip.org).
|
I wonder whether Timer created with
```
int eloop_register_timeout (unsigned int secs,
unsigned int usecs,
eloop_timeout_handler handler,
void * eloop_data,
void * user_data
... |
No, the timer is run in the event loop thread when it expires.
|
I want to link an existing shared library (FlashRuntimeExtensions.so) to my C-code while compiling my own shared library. But whatever I try I always get the same error; that the file is in a wrong format. Does anybody have an idea on how to solve this?
Here is my compile command:
```
$ g++ -Wall ane.c FlashRuntimeE... |
Your command line tries to generate x86 code and link it to ARM code using the native g++ available in your distribution.
This will not work. Use the Android NDK available here:http://developer.android.com/tools/sdk/ndk/index.html
The NDK includes a set of cross-toolchains (compilers, linkers, etc..) that can genera... |
Which is the plug in I need to install to program C in my eclipse
How I install it?
|
You need to install eclipseCDT(C Development Kit). You can choose which compiler you want to use with CDT. You can read morehere.
|
OK, I'm trying to print the decimal/hexadecimal version of a relatively bigunsigned long longand the results I'm getting are quite weird...
The code :
```
unsigned long long a = 1llu<<63;
printf("decimal = %llu\n",a);
printf("hexadecimal = %llx\n",a);
```
The output :
```
decimal = 9223372036854775808
hexadecimal... |
Since five is not a factor of any power of two, no power of two ends in zero. Your other source which gave9223372036854780000is incorrect.
|
Hello I'm trying to convert a decimal value to a hex using C in order to store it on my variablechar data[]and use the data later for something else. Does any one know how I can do it? I'm new to C
|
You can use the%xformat specifier and asprintf. Passdataas the first parameter, and the value to be printed as the last parameter:
```
int value = 12345;
char data[16];
sprintf(data, "%x", value); // This produces 3039
```
Link to ideone.
|
I want to get the elements of an array of characters, but no success at all, the problem is that I only get the first and last element and nothing more, my code is:
```
void getcharacters(char *cad)
{
int l;
int *i;
l=strlen(cad);
for (i=&cad[0];i<&cad[l];i++){
printf("%c\n",*cad);
}
}
```
any help?
Thanks... |
The size of anintcan be as big as 4 x the size of achar, so when you doi++you are actually skipping 3 chars.
Also, you print out*cadinstead of*i.
To fix changeitochar*and print*iinstead of*cad
|
I'm currently writing small simple C programs. As of now my Makefiles have consisted of text something along the lines of:
```
program_name:
clang -o program_name program_name.c
```
Is this all I need? I wasn't sure if I needed to establish dependencies between .o and .h files, even if they don't necessarily e... |
You are working too hard. You should simplify your Makefile to 2 lines:
```
CC=clang
program_name: some.h
```
There is no need to specify the dependency onprogram_name.oorprogram_name.c, since those are implied. There is also no need to give the rule explicitly, since you are using the default rule. Dependencies ... |
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened,visit the help center.Closed10 years ago.
I have this problem with C.
I have... |
You are compiling your code as C++, in which the code you've used is not valid. For C though, it is valid and youshould not add any cast.
Note, however, that the argument tomalloc()is inchars, so "100" is a bit random. If you want 100 integers, do:
```
a = malloc(100 * sizeof *a);
```
|
Here is the deal. I want to write a kernel module which depends on the kernel type (32 or 64 bit).
There are some lines of code which I want to be included in the module if and only if the kernel is 32 bit and some lines of code which should be included iff kernel is 64 bit.
Is there anything like #if LINUX_VERSION_C... |
You can check for CONFIG_X86_64 and CONFIG_X86_32 - If the arch is x86. For other architectures there are similiar CONFIG options.
|
i have a char matrix like below
```
char files[4][10];
```
And in the matrix these char arrays are hold.
```
file1.txt
file2.txt
file3.txt
file4.txt
```
when i try to use fopen with this matrix,i can not open the file.My code is this:
```
FILE *file;
file = fopen(files[0],"rb");
if(file == NULL){
... |
Two things would come to mind:
file1.txt is not available in the directory you call the executableYou do not show how you initialize your files array. Might be that you are not 0 terminating the string.
|
I want a command that will completely ignore a function. Somebody once showed me the command, but I can't find it in the manual.
```
void a()
{
return;
}
#pragma gcc_disable
void a ()
{
return q09w8uifsdf
}
#include <stdio.h>
int main ()
{
a();
}
```
|
Umm... you mean this?
```
void a()
{
return;
}
#if 0
void a ()
{
return q09w8uifsdf
}
#endif
#include <stdio.h>
int main ()
{
a();
}
```
|
I was wondering, if we haveif-elsecondition, then what is computationally more efficient to check: using theequal tooperator or thenot equal tooperator? Is there any difference at all?
E.g., which one of the following is computationally efficient, both cases below will do same thing, but which one is better (if there... |
Generally it shouldn't matter for performance which operator you use. However it is recommended for branching that the most likely outcome of the if-statement comes first.
|
I am new to multiple processes in C.
Once a new child process is created in C, what all code is copied to that processes.
I am confused as I am trying to create a child process but what would happen in its int main() function, since I am creating this child process from some other function.
I am working on Windows ... |
On Windows, you should have a look at the winapiCreateProcess()function which creates a new process that runs the command you want, also check this example inMSDN.
|
Which is the plug in I need to install to program C in my eclipse
How I install it?
|
You need to install eclipseCDT(C Development Kit). You can choose which compiler you want to use with CDT. You can read morehere.
|
OK, I'm trying to print the decimal/hexadecimal version of a relatively bigunsigned long longand the results I'm getting are quite weird...
The code :
```
unsigned long long a = 1llu<<63;
printf("decimal = %llu\n",a);
printf("hexadecimal = %llx\n",a);
```
The output :
```
decimal = 9223372036854775808
hexadecimal... |
Since five is not a factor of any power of two, no power of two ends in zero. Your other source which gave9223372036854780000is incorrect.
|
Hello I'm trying to convert a decimal value to a hex using C in order to store it on my variablechar data[]and use the data later for something else. Does any one know how I can do it? I'm new to C
|
You can use the%xformat specifier and asprintf. Passdataas the first parameter, and the value to be printed as the last parameter:
```
int value = 12345;
char data[16];
sprintf(data, "%x", value); // This produces 3039
```
Link to ideone.
|
I want to get the elements of an array of characters, but no success at all, the problem is that I only get the first and last element and nothing more, my code is:
```
void getcharacters(char *cad)
{
int l;
int *i;
l=strlen(cad);
for (i=&cad[0];i<&cad[l];i++){
printf("%c\n",*cad);
}
}
```
any help?
Thanks... |
The size of anintcan be as big as 4 x the size of achar, so when you doi++you are actually skipping 3 chars.
Also, you print out*cadinstead of*i.
To fix changeitochar*and print*iinstead of*cad
|
I'm currently writing small simple C programs. As of now my Makefiles have consisted of text something along the lines of:
```
program_name:
clang -o program_name program_name.c
```
Is this all I need? I wasn't sure if I needed to establish dependencies between .o and .h files, even if they don't necessarily e... |
You are working too hard. You should simplify your Makefile to 2 lines:
```
CC=clang
program_name: some.h
```
There is no need to specify the dependency onprogram_name.oorprogram_name.c, since those are implied. There is also no need to give the rule explicitly, since you are using the default rule. Dependencies ... |
I am working on a program where I'm reading from a Tap. The only issue is, I have no clue how to detect the end of one transmission to the tap and the start of another.
Does reading from the tap act the same way as a SOCK_STREAM ?
|
Tun/tap tries to look like a regular ethernet controller, but the tap device itself is accessed just like any other file descriptor.
Since it pretends to be an ethernet controller, you have to know in advance how big the ethernet frame itself was that was transmitted - this comes either from the software bridge that ... |
I want the program to dump core on crash on Linux for debugging purpose. How do I enable this feature - does this require any changes in the program ?
|
You can either enable it for yourself by doing:
```
ulimit -c unlimited
```
If you want this to be persistent put it in ~/.profile
Alterantively, you can enable core dumps for all users on the system put the following line in /etc/sercurity/limits.conf (at least on ubuntu):
```
* 0 core -1
```
|
Normally strcmp is used with two arguments [e.g. strcmp(str1,"garden")], and it will return 0 if both are the same.
Is it possible to compare part of the input, say the first five character of the input? (for example,strcmp(str1,"garde",5))
```
#include <stdio.h>
#include<string.h>
int main(void) {
char str1[]... |
Use strncmp:
```
if (strncmp(str, "test", 4) == 0) { printf("it matches!"); }
```
Seehttp://www.cplusplus.com/reference/cstring/strncmp/for more info.
|
I cant figure out how to count the number of times the largest number was entered. please help. if i initialise s to 0 it doesnt count the first number if its the highest.
```
#include <stdio.h>
int main (void)
{
int times=0,n,m,i,max;
printf("How many numbers(n) you going to enter:\n");
scanf("%d",&n... |
You need to resettimesto1:
```
if(m == max) {
times++;
} else if(m > max)
max = m;
times = 1;
}
```
And initialize it to1:
```
int times = 1, n, m, i, max;
```
|
I got this code to successfully compilehttp://dis-dot-dat.net/index.cgi?item=jacktuts/starting/wholesimple
How ever when I run it it tells me the following
usage: jack_simple_client
So I'm thinking it needs some kind of input so i try to run it like the following
./jack_simple_client 0
it tells me the following
... |
You have to start a jackd server first, usually with the alsa backend.
```
jackd -d alsa
```
now jack_simple_client on another terminal should work
```
jack_simple_client
```
|
I made a server that usesselect()to check witch of the socket descriptors have data in them, but apparently select marks a socket to be ready to read from even after the client disconnects, and I get garbage values.
I have found this post on stack overflow:
select (with the read mask set) will return with the handle... |
If a call toread()on a socket (file) descriptor returns0, that simply means the other side of the connection had shutdown and closed the connection.
Note: Aselect()waiting for possible "events" on set(s) of socket (file) descriptors will also return when a connection represented by one of thefd_set's passed toselect(... |
How can I in my make-file use option-std=c99or-std=gnu99to compile my C code?
```
-include ../../../Common/C/Make.cfg
### target ###
TARGET_NAME = myRec
### Objects, sources ###
# C source files
CSRCS = \
myRec.c
LDLIBS ?= -lNBiometrics -lNMedia -lNCore
include ../../../Common/C/Make.rules
```
|
You need to set theCFLAGSmakefile variable.
|
I just saw the following code among the successful submissions at codechef.
http://www.codechef.com/viewplaintext/1595846
I used to think that
```
float max(int n,int arr[n][n])
{....}
```
is not allowed in C++ (as 'n' is a variable). My CodeBlocks (on windows) with MinGW [gcc 4.4] gives compile time error. that "... |
Variable-length automatic arrays are allowed in ISO C99, and as an extension GCC accepts them in C90 mode and in C++. These arrays are declared like any other automatic arrays, but with a length that is not a constant expression.
Ref:http://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html
|
I'm working on a software designed to compile and run on Linux. I was recently asked to cross-compile it for Android using the NDK, which was surprisingly straightforward.
To do this quickly, we just compiled the source,without writing any JNI wrapper. I copied the resulting binaries withadb pushto an emulator (roote... |
http://www.ibm.com/developerworks/opensource/tutorials/os-androidndk/index.htmli found the nice tutorial in IBM developersworks aboutAndroid NDK
|
I want to change some kernel source files for network stack testing so is there any way to get kernel source code for RHEL6 Enterprise edition and how to apply the changes to get results?
|
Herefrom redhat ftp, you may get what you want.
Example:kernel-2.6.32-220.17.1.el6.src.rpm
|
```
<?php
$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
echo "Got Irix";
}
if (in_array("mac", $os)) {
echo "Got mac";
}
?>
```
Is there some function in C which does similar thing toin_arrayin PHP?
|
Nope, but you can implement like this
```
typedef int (*cmpfunc)(void *, void *);
int in_array(void *array[], int size, void *lookfor, cmpfunc cmp)
{
int i;
for (i = 0; i < size; i++)
if (cmp(lookfor, array[i]) == 0)
return 1;
return 0;
}
int main()
{
char *str[] = {"this is te... |
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened,visit the help center.Closed10 years ago.
How do I create anintarray of size ... |
mallocis usually a good idea if you want something like 20MB. Most stacks are smaller and will crash the program if you try.
```
int *myInts = (int *)malloc(20*1024*1024);
```
or place it as a static/global variable:
```
int myArray[20*1024*1024/sizeof(int)];
```
or withsbrk
```
int *myInt = sbrk(0); /* Get the c... |
I am new to C, from a Java background.
If I have a struct that is initialized on the fly with data that comes from functions inside of the struct definition, when do those functions get called? When does this code run? Is it just on the first reference tosample_struct_table[i]?
```
static struct sample_struct {
... |
The functions get called when you call them. In your example, all you are doing is setting the field of the structure to the function pointer. The function is not called, you just have a pointer pointing to it.
|
I'm trying to use the following DeviceContext struct to get some Graphics Driver information.
http://msdn.microsoft.com/en-us/library/windows/desktop/dd183569%28v=vs.85%29.aspx
In the documentation, the one parameter says it can be any "reasonable combination" of the given options.
What type are they? Are they def... |
The values of the flags are defined in the page you referenced. The combined value is created by ORing the fields together, for example:
```
(DISPLAY_DEVICE_ACTIVE | DISPLAY_DEVICE_PRIMARY_DEVICE)
```
|
When we created shared object file why we do versioning of it, for example
```
/libnetsnmp.so.5.0.9
libzebra.so -> libzebra.so.0.0.0
libzebra.so.0 -> libzebra.so.0.0.0
```
Isn't creating just ".so" file is not enough ?
|
It may be needed to make multiple versions of the library coexist, having one particular version as the default; or to see at glance which precise version of library is installed, and the symlink lets the applications refer to the non-versioned filename (which is important, otherwise you would have to recompile the ap... |
Anyone have any idea why this works:
```
int main(void)
{
char action;
int *i;
*i=10;
printf("%d",*i);
action='C';
printf("%c",action);
}
```
but this doesnt
```
int main(void)
{
char action='C';
int *i;
*i=10;
printf("%d",*i);
printf("%c",action);
}
```
I am getting no errors but it will not run! cant see why tha... |
The behavior of your code is undefined. There's no logic in its behavior. It is essentially random. Trying to analyze why some irrelevant "little difference" changes the behavior you observed in your experiments is a waste of time.
|
This question already has answers here:print a __m128i variable(4 answers)Closed4 years ago.
I have some code that uses SIMD optimization and various __m128i variables. Obviously, printf can't handle them. Is there an easy way for me to print their contents?
I'm using Visual Studio 2010 with C/C++.
|
Use this function to print them:
```
void print128_num(__m128i var)
{
uint16_t *val = (uint16_t*) &var;//can also use uint32_t instead of 16_t
printf("Numerical: %i %i %i %i %i %i %i %i \n",
val[0], val[1], val[2], val[3], val[4], val[5],
val[6], val[7]);
}
```
You split 128bits into ... |
I want to pass an integer to a function, have the function edit it and then pass back the integer to the main function. I am working on this but it isn't working.
Here is my code:
```
int update_SEG_values(int DIGIT_1, int DIGIT_2) {
// How many tens in the "TEMP_COUNT".
DIGIT_2 = ((TEMP_COUNT) / 10);
... |
You can only return one value in C
when you give :
```
return(DIGIT_1, DIGIT_2);
```
due to the comma operatorDIGIT_2will be returned. For more info referhttp://en.wikipedia.org/wiki/Comma_operator
You can get your job done by using pointers or structures (both digits will be part of same structure and you return ... |
I'm using the standardmktimefunction to turn astruct tminto an epoch time value. Thetmfields are populated locally, and I need to get the epoch time as GMT.tmhas agmtofffield to allow you to set the local GMT offset in seconds for just this purpose.
But I can't figure out how togetthat information. Surely there must ... |
Just do the following:
```
#define _GNU_SOURCE /* for tm_gmtoff and tm_zone */
#include <stdio.h>
#include <time.h>
/* Checking errors returned by system calls was omitted for the sake of readability. */
int main(void)
{
time_t t = time(NULL);
struct tm lt = {0};
localtime_r(&t, <);
printf("Offset to GM... |
I am trying to compile some source code but when i run the command
make -f android-9-armv7.mk
I get the following error
android-9-armv7.mk:1:*missing separator. Stop.
This is the contents of the file above:
And I have set the IMAGINE_PATH variable as well, cant seem to figure it out.
link ../imagine/make/shortcut... |
I don't know where you've taken the sources, but all theandroid-9-armv7.mkfiles from different projects on that git has following content:
```
../imagine/make/shortcut/common-builds/android-9-armv7.mk
```
...there is nolinkkeyword, which probably is why you get this error.
Also, please be informed that you're build... |
Using the code
```
sscanf(argv[1], "%d", &num1);
sscanf(argv[2], "%c", &op);
sscanf(argv[3], "%d", &num2);
if ((op != '-')||(op != '*')||(op != '/')||(op != '+'))
{
puts("Error:");
printf("'%c' is not a valid operator", op);
return 0;
}
```
Compiles fine.
However, do... |
Makes sense, since your condition is always true.
```
(op != '-')||(op != '*')||(op != '/')||(op != '+')
```
or even
```
(op != '-')||(op != '*')
```
will always evaluate totrue.
You're basically saying "Ifopis not-ORopis not*... do whatever".
You probably meant to use&&instead.
|
This is my code for a simple selection sort.usually the complexity (time) for a sort is number of iterations it has taken for sorting O(n^2) in case of selection sort
When I dry ran this code against sample string of 98765, it gave me 25 iterations.
Just to cross check with my dry ran output i put 2 vbl- noi and noj i... |
number of iterations is always 15 (5+4+3+2+1) because in your loops there arej<5andi<5. So your code complexity is O(n^0) because in your case n is 5
|
Using
```
int main(int argc, char *argv[])
{
double number1, number2;
char operator;
number1 =atof (argv[0]);
operator =argv[1]; // line 29
number2 =atof (argv[2]);
```
Compiler complains saying
29 warning: assignment makes integer from pointer without a cast
[enabled by default]
|
argv[1] is a pointer to char, you can't assign it to a char. either transform operator to char * or try operator = *(argv[1]);
|
When we created shared object file why we do versioning of it, for example
```
/libnetsnmp.so.5.0.9
libzebra.so -> libzebra.so.0.0.0
libzebra.so.0 -> libzebra.so.0.0.0
```
Isn't creating just ".so" file is not enough ?
|
It may be needed to make multiple versions of the library coexist, having one particular version as the default; or to see at glance which precise version of library is installed, and the symlink lets the applications refer to the non-versioned filename (which is important, otherwise you would have to recompile the ap... |
Anyone have any idea why this works:
```
int main(void)
{
char action;
int *i;
*i=10;
printf("%d",*i);
action='C';
printf("%c",action);
}
```
but this doesnt
```
int main(void)
{
char action='C';
int *i;
*i=10;
printf("%d",*i);
printf("%c",action);
}
```
I am getting no errors but it will not run! cant see why tha... |
The behavior of your code is undefined. There's no logic in its behavior. It is essentially random. Trying to analyze why some irrelevant "little difference" changes the behavior you observed in your experiments is a waste of time.
|
This question already has answers here:print a __m128i variable(4 answers)Closed4 years ago.
I have some code that uses SIMD optimization and various __m128i variables. Obviously, printf can't handle them. Is there an easy way for me to print their contents?
I'm using Visual Studio 2010 with C/C++.
|
Use this function to print them:
```
void print128_num(__m128i var)
{
uint16_t *val = (uint16_t*) &var;//can also use uint32_t instead of 16_t
printf("Numerical: %i %i %i %i %i %i %i %i \n",
val[0], val[1], val[2], val[3], val[4], val[5],
val[6], val[7]);
}
```
You split 128bits into ... |
I want to pass an integer to a function, have the function edit it and then pass back the integer to the main function. I am working on this but it isn't working.
Here is my code:
```
int update_SEG_values(int DIGIT_1, int DIGIT_2) {
// How many tens in the "TEMP_COUNT".
DIGIT_2 = ((TEMP_COUNT) / 10);
... |
You can only return one value in C
when you give :
```
return(DIGIT_1, DIGIT_2);
```
due to the comma operatorDIGIT_2will be returned. For more info referhttp://en.wikipedia.org/wiki/Comma_operator
You can get your job done by using pointers or structures (both digits will be part of same structure and you return ... |
I'm using the standardmktimefunction to turn astruct tminto an epoch time value. Thetmfields are populated locally, and I need to get the epoch time as GMT.tmhas agmtofffield to allow you to set the local GMT offset in seconds for just this purpose.
But I can't figure out how togetthat information. Surely there must ... |
Just do the following:
```
#define _GNU_SOURCE /* for tm_gmtoff and tm_zone */
#include <stdio.h>
#include <time.h>
/* Checking errors returned by system calls was omitted for the sake of readability. */
int main(void)
{
time_t t = time(NULL);
struct tm lt = {0};
localtime_r(&t, <);
printf("Offset to GM... |
I am trying to compile some source code but when i run the command
make -f android-9-armv7.mk
I get the following error
android-9-armv7.mk:1:*missing separator. Stop.
This is the contents of the file above:
And I have set the IMAGINE_PATH variable as well, cant seem to figure it out.
link ../imagine/make/shortcut... |
I don't know where you've taken the sources, but all theandroid-9-armv7.mkfiles from different projects on that git has following content:
```
../imagine/make/shortcut/common-builds/android-9-armv7.mk
```
...there is nolinkkeyword, which probably is why you get this error.
Also, please be informed that you're build... |
Using the code
```
sscanf(argv[1], "%d", &num1);
sscanf(argv[2], "%c", &op);
sscanf(argv[3], "%d", &num2);
if ((op != '-')||(op != '*')||(op != '/')||(op != '+'))
{
puts("Error:");
printf("'%c' is not a valid operator", op);
return 0;
}
```
Compiles fine.
However, do... |
Makes sense, since your condition is always true.
```
(op != '-')||(op != '*')||(op != '/')||(op != '+')
```
or even
```
(op != '-')||(op != '*')
```
will always evaluate totrue.
You're basically saying "Ifopis not-ORopis not*... do whatever".
You probably meant to use&&instead.
|
This is my code for a simple selection sort.usually the complexity (time) for a sort is number of iterations it has taken for sorting O(n^2) in case of selection sort
When I dry ran this code against sample string of 98765, it gave me 25 iterations.
Just to cross check with my dry ran output i put 2 vbl- noi and noj i... |
number of iterations is always 15 (5+4+3+2+1) because in your loops there arej<5andi<5. So your code complexity is O(n^0) because in your case n is 5
|
Using
```
int main(int argc, char *argv[])
{
double number1, number2;
char operator;
number1 =atof (argv[0]);
operator =argv[1]; // line 29
number2 =atof (argv[2]);
```
Compiler complains saying
29 warning: assignment makes integer from pointer without a cast
[enabled by default]
|
argv[1] is a pointer to char, you can't assign it to a char. either transform operator to char * or try operator = *(argv[1]);
|
I came across some issue in which my application gives different results for relase & debug mode.
Is there any tool available by which I can check memory map difference & variable values of a function between two modes.
|
If you are using a Unix-like operating system, you might want to have a look atValgrind. Output differences between debug and release mode are often due to the executables having a different memory layout, thus exposing memory-related bugs that are not otherwise visible.
|
I'm using xcode and want to get the path where my app is running without the app name at the end of the path, but i have tried:
```
printf("%s\n", argv[0]);
```
it give me the right path where my app is runing but it ends with /my app name, how can i remove the app name?
|
usedirname
```
#include <iostream>
#include <libgen.h>
int main(int argc, char* argv[])
{
std::string dir = dirname(argv[0]);
std::cout << dir << std::endl;
}
```
Run application:
```
$/data/temp/test
```
output:
```
$/data/temp
```
|
I'm working to create a library for my app in C. I want to parse a XML file in my code.
So, how can i do it in C ?
I know its java implementation but how can i parse a XML in my C code ?
What are the libraries that can be used for the purpose ?
|
I suggestExpat, I've used with many projects and it is very simple to use and has extremely small overhead. Its code base is also quite stable.
Expat is an XML parser library written in C. It is a stream-oriented parser in which an application registers handlers for things the parser might find in the XML document (l... |
Assuming we dereference correctly and use the integer right, is this a good programming practice?
```
union {
int x;
struct node * next;
};
```
|
Unions are rather low-level language feature. There are no meaningful reason for any restrictive "good programming practices" to exist with regards to which types can reside together in a union. The purpose of union is to "multiplex" memory usage: to save space by storing several unrelated objects with non-overlapping... |
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened,visit the help center.Closed10 years ago.
```
void main(){
int i;
... |
From theman page:Upon successful return, these functions return the number of characters printed.... If an output error is encountered, a negative value is returned.
So you are getting9andibecauseprintfwrote out9and1characters respectively.
This is also relevant:Why does printf return a value?
|
Is this my bug or a bug/assertion fail inmallocitself?
alloc.c:2451: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *)
&((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct
malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size)= (unsigned long)((((__builtin_offsetof (struct malloc_chunk... |
The most likely explanation is that there's a memory bug in your program (writing to freed memory, buffer overrun, etc). An outright bug inmalloc()is far less likely.
|
I have the following code and am asked to how many times "A", "B", "C", "D", "E" will be printed
```
fun() {
printf("A");
fork();
printf("B");
if (fork() != 0) {
printf("C");
fork();
printf("D");
}
printf("E");
}
```
so it should be:
```
A
A
B
E
```
im not sure if my answer above is cor... |
From thedocumentation:
On success, the PID of the child process is returned in the parent, and 0 is returned in the child. On failure, -1 is returned in the parent, no child process is created, and errno is set appropriately.
|
I have a makefile which does what I want with the compilation but I want it also to make a library instead of only object files.
```
CC=gcc
CFLAGS=-g -Wall
DEPS = tree.h
OBJ = main.o tree.o
%.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
tree: $(OBJ)
$(CC) -o $@ $^ $(CFLAGS)
clean:
rm -f *.o tree
```
No... |
This should do what you want:
```
%.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
lib%.a: %.o
ar -r $@ $^
main: $(OBJ) $(DEPS:%.h=lib%.a)
$(CC) -o $@ $^ $(CFLAGS) $(DEPS:%.h=-l%) -L.
```
Note that this only works in GNU Make (in particular, the%in$(DEPS:%.h=lib%.a)is a GNU-specific extension).
|
```
typedef struct s {
char name[20];
char last_name[20];
int height;
} s_t;
s_t my_s_t;
my_s_t.name = "John";
```
I get "Incompatible types in assignment" for the last line.
What am I doing wrong?
|
```
my_s_t.name = "John";
```
nameis a char array. So you can´t directly assign a string literal to it. You can usestrcpyor similar function to copy the string literal OR declarenameaschar*.
Options:
1)
```
typedef struct s {
char name[20];
char last_name[20];
int height;
} s_t;
s_t my_s_t;
strcpy(my_s_t.name, "J... |
Is the following code safe if a null pointer is passed in?
```
if(ptr && *ptr == value)
{
//do something
}
```
Does the order of the checks matter? Does it work if I change it to this?
```
if(*ptr == value && ptr)
{
//do something
}
```
|
The former is correct and safe, the latter is not.
The built-in&&operator hasshort-circuit semantics, meaning that the second argument is evaluated if and only if the first one is true.
(This is not the case foroverloadedoperators.)
|
I am trying to get a Python regex to search through a .c file and get the function(s) inside it.
For example:
```
int blahblah(
struct _reent *ptr __attribute__((unused)),
const char *old,
const char *new
)
{
...
```
I would want to getblahblahas the function.
This regex doesn't work for me, it keeps o... |
(?<=(int\s)|(void\s)|(string\s)|(double\s)|(float\s)|(char\s)).*?(?=\s?\()
http://regexr.com?3332t
This should work for what you want. Just keep adding types that you need to catch.
re.findall(r'(?<=(?<=int\s)|(?<=void\s)|(?<=string\s)|(?<=double\s)|(?<=float\s)|(?<=char\s)).*?(?=\s?\()', string)will work for py... |
Why isn't it in C (or C++) allowed?
I mean this:
```
ucell GetPlayerPosPositionData[5];
GetPlayerPosPositionData = {4*sizeof(cell),playerid,0,sizeof(cell),2*sizeof(cell)};//this does not work, error
//normal assignment
GetPlayerPosPositionData[1] = playerid;
GetPlayerPosPositionData[2] = 0;
GetPlayerPosPositionData... |
Because arrays are not assignable. You can initialize them at the point of declaration or you can assign them on a per-element basis, but that's it. This would work:
```
ucell GetPlayerPosPositionData[] = {4*sizeof(cell),
playerid,
0,
... |
I want to communicate with device which firmware is describedthere
Hereis my code. But in that code I receive nulls, negative numbers and other trash. What's wrong in my code?
|
You should first make a check to find the synchronization bytes that are first in the message struct. Look for the values 0xA5 and 0x5A. When you find those you can start to decode the rest of the message.
It seems like the ModEEG thing is just outputting a steady stream of bytes so you have to look for the message s... |
I need a condition for a do-while loop that means the loop is repeated (asking user to enter data again) until it is an integer number and between 1 and 25.
```
while (!isdigit(data) || data < 1 || data > 25);
```
This just throws out a runtime error and I'm not sure why.
|
Try this:
```
do {
/* Read from input and store it in data */
} while( !isdigit(data) || !( data > 1 && data < 25 ) );
```
|
I can't send chunks of data bigger than420bytes. For example if i try to send421 bytes, i can't read it withReadFile. If I check the maislot info withGetMailslotInfo( handleRead, 0, &msgSize, 0, 0 );thenmsgSizewill always be-1.
So this will never work for me:
```
err = WriteFile( handleWrite, wcharArrayToSend, 421, ... |
PerMSDN's documentation on mailslots:
The data in a mailslot message can be in any form, but cannot be larger than 424 bytes when sent between computers.To send messages that are larger than 424 bytes between computers, usenamed pipesorWindows Socketsinstead.
|
I'm trying to write a shell, and part of its construction is executing code from a user-inputted string (buffer). However, when I attempt to execvp the string with additional inputs (ae. echo a), it always screws the pooch and returns -1. I'm at a loss as to why. Here's the relevant pieces:
```
char * buffer = calloc... |
The argumentbufferis wrong. The second argument ofexecvpis an array of pointers. With this cast, you are hidding a compiler warning, but it does not work.
|
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable,visit the help cen... |
This is a sum of geometric series withlog2nelements. The sum depends on yourn, but in any case it's bounded by2n. Theory is here:http://en.wikipedia.org/wiki/Geometric_progression
|
I am trying to do a dynamic Collatz algorithm but seem to have incorrect answers beyond at least 626331 or greater. all of the others seem to be correct. ive been working on this for hours and cant figure out what my problem is. can anyone give me a suggestion to help. thanks
```
int DynamicCollatz::DynCollatzConject... |
The maximum value generated by the Collatz algorithm for value 626331 is:
```
o = 626331 m = 7222283188 c = 508
```
That number is tidily larger than will fit into a 32-bit (unsigned)int. (Thecis the count of the steps taken to get to 1.)
I used thisbcscript (which I have stashed away because the Collatz algorithm... |
```
typedef struct s {
char name[20];
char last_name[20];
int height;
} s_t;
s_t my_s_t;
my_s_t.name = "John";
```
I get "Incompatible types in assignment" for the last line.
What am I doing wrong?
|
```
my_s_t.name = "John";
```
nameis a char array. So you can´t directly assign a string literal to it. You can usestrcpyor similar function to copy the string literal OR declarenameaschar*.
Options:
1)
```
typedef struct s {
char name[20];
char last_name[20];
int height;
} s_t;
s_t my_s_t;
strcpy(my_s_t.name, "J... |
Is the following code safe if a null pointer is passed in?
```
if(ptr && *ptr == value)
{
//do something
}
```
Does the order of the checks matter? Does it work if I change it to this?
```
if(*ptr == value && ptr)
{
//do something
}
```
|
The former is correct and safe, the latter is not.
The built-in&&operator hasshort-circuit semantics, meaning that the second argument is evaluated if and only if the first one is true.
(This is not the case foroverloadedoperators.)
|
I am trying to get a Python regex to search through a .c file and get the function(s) inside it.
For example:
```
int blahblah(
struct _reent *ptr __attribute__((unused)),
const char *old,
const char *new
)
{
...
```
I would want to getblahblahas the function.
This regex doesn't work for me, it keeps o... |
(?<=(int\s)|(void\s)|(string\s)|(double\s)|(float\s)|(char\s)).*?(?=\s?\()
http://regexr.com?3332t
This should work for what you want. Just keep adding types that you need to catch.
re.findall(r'(?<=(?<=int\s)|(?<=void\s)|(?<=string\s)|(?<=double\s)|(?<=float\s)|(?<=char\s)).*?(?=\s?\()', string)will work for py... |
Why isn't it in C (or C++) allowed?
I mean this:
```
ucell GetPlayerPosPositionData[5];
GetPlayerPosPositionData = {4*sizeof(cell),playerid,0,sizeof(cell),2*sizeof(cell)};//this does not work, error
//normal assignment
GetPlayerPosPositionData[1] = playerid;
GetPlayerPosPositionData[2] = 0;
GetPlayerPosPositionData... |
Because arrays are not assignable. You can initialize them at the point of declaration or you can assign them on a per-element basis, but that's it. This would work:
```
ucell GetPlayerPosPositionData[] = {4*sizeof(cell),
playerid,
0,
... |
I want to communicate with device which firmware is describedthere
Hereis my code. But in that code I receive nulls, negative numbers and other trash. What's wrong in my code?
|
You should first make a check to find the synchronization bytes that are first in the message struct. Look for the values 0xA5 and 0x5A. When you find those you can start to decode the rest of the message.
It seems like the ModEEG thing is just outputting a steady stream of bytes so you have to look for the message s... |
I need a condition for a do-while loop that means the loop is repeated (asking user to enter data again) until it is an integer number and between 1 and 25.
```
while (!isdigit(data) || data < 1 || data > 25);
```
This just throws out a runtime error and I'm not sure why.
|
Try this:
```
do {
/* Read from input and store it in data */
} while( !isdigit(data) || !( data > 1 && data < 25 ) );
```
|
I can't send chunks of data bigger than420bytes. For example if i try to send421 bytes, i can't read it withReadFile. If I check the maislot info withGetMailslotInfo( handleRead, 0, &msgSize, 0, 0 );thenmsgSizewill always be-1.
So this will never work for me:
```
err = WriteFile( handleWrite, wcharArrayToSend, 421, ... |
PerMSDN's documentation on mailslots:
The data in a mailslot message can be in any form, but cannot be larger than 424 bytes when sent between computers.To send messages that are larger than 424 bytes between computers, usenamed pipesorWindows Socketsinstead.
|
I'm trying to write a shell, and part of its construction is executing code from a user-inputted string (buffer). However, when I attempt to execvp the string with additional inputs (ae. echo a), it always screws the pooch and returns -1. I'm at a loss as to why. Here's the relevant pieces:
```
char * buffer = calloc... |
The argumentbufferis wrong. The second argument ofexecvpis an array of pointers. With this cast, you are hidding a compiler warning, but it does not work.
|
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable,visit the help cen... |
This is a sum of geometric series withlog2nelements. The sum depends on yourn, but in any case it's bounded by2n. Theory is here:http://en.wikipedia.org/wiki/Geometric_progression
|
Why isn't it in C (or C++) allowed?
I mean this:
```
ucell GetPlayerPosPositionData[5];
GetPlayerPosPositionData = {4*sizeof(cell),playerid,0,sizeof(cell),2*sizeof(cell)};//this does not work, error
//normal assignment
GetPlayerPosPositionData[1] = playerid;
GetPlayerPosPositionData[2] = 0;
GetPlayerPosPositionData... |
Because arrays are not assignable. You can initialize them at the point of declaration or you can assign them on a per-element basis, but that's it. This would work:
```
ucell GetPlayerPosPositionData[] = {4*sizeof(cell),
playerid,
0,
... |
I want to communicate with device which firmware is describedthere
Hereis my code. But in that code I receive nulls, negative numbers and other trash. What's wrong in my code?
|
You should first make a check to find the synchronization bytes that are first in the message struct. Look for the values 0xA5 and 0x5A. When you find those you can start to decode the rest of the message.
It seems like the ModEEG thing is just outputting a steady stream of bytes so you have to look for the message s... |
I need a condition for a do-while loop that means the loop is repeated (asking user to enter data again) until it is an integer number and between 1 and 25.
```
while (!isdigit(data) || data < 1 || data > 25);
```
This just throws out a runtime error and I'm not sure why.
|
Try this:
```
do {
/* Read from input and store it in data */
} while( !isdigit(data) || !( data > 1 && data < 25 ) );
```
|
I can't send chunks of data bigger than420bytes. For example if i try to send421 bytes, i can't read it withReadFile. If I check the maislot info withGetMailslotInfo( handleRead, 0, &msgSize, 0, 0 );thenmsgSizewill always be-1.
So this will never work for me:
```
err = WriteFile( handleWrite, wcharArrayToSend, 421, ... |
PerMSDN's documentation on mailslots:
The data in a mailslot message can be in any form, but cannot be larger than 424 bytes when sent between computers.To send messages that are larger than 424 bytes between computers, usenamed pipesorWindows Socketsinstead.
|
I'm trying to write a shell, and part of its construction is executing code from a user-inputted string (buffer). However, when I attempt to execvp the string with additional inputs (ae. echo a), it always screws the pooch and returns -1. I'm at a loss as to why. Here's the relevant pieces:
```
char * buffer = calloc... |
The argumentbufferis wrong. The second argument ofexecvpis an array of pointers. With this cast, you are hidding a compiler warning, but it does not work.
|
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable,visit the help cen... |
This is a sum of geometric series withlog2nelements. The sum depends on yourn, but in any case it's bounded by2n. Theory is here:http://en.wikipedia.org/wiki/Geometric_progression
|
Can I embed the C code from Visual C project in the Xilinx Microblaze? I have already created the EDK design of hardware and want to import my Visual studio based design of FIR filter into the Xilinx SDK. I don't know how to do it. Is it even possible? Any tips? Thanks!
|
Recently I am playing with Spartan06 from xilinx. As far as I can understand that youcannotimport Visual C project to Xilinx Microblaze.
This is because you need to use a cross compiler to target the Microblaze processor. Xilinx uses the CodeSourcery's gcc to do that. That is why you need to use the SDK to compile th... |
I have several small programs that require infinitely looping over the integer setZsub n. I often write the code in this manor:
```
int x = 0;
int n = 13; //or some other prime
while(1) {
//do stuff dependent on x
++x;
x %= n;
}
```
I write code mostly in C/C++ & Java so I was wondering:
Is there a way to inc... |
Have you considered:
```
x = (x + 1 == n ? 0: x + 1);
```
The chances are thex + 1will optimise to one instruction and at least you are guaranteed to never use division (which a bad optimiser might use when%is involved).
|
System: Ubuntu 12.04Compiler: gcc (version: 4.6.3)
My idea is to write a client-server application to exchange data via the serial port.
But my problem is, when I execute the code-snippet below, open returns the same file descriptor
if I start two independent processes:
The first process opens "/dev/ttyS0".The 2nd ... |
It's totally normal.File descriptoris just an offset into in-kernel per-process open file table.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.