question stringlengths 25 894 | answer stringlengths 4 863 |
|---|---|
here is my piece of code
```
#include<stdio.h>
main ()
{
extern int i;
i=20;
printf("%d",i);
}
```
When I compile it I get error
```
ka2.c: In function ‘main’:
ka2.c:6: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘long unsigned int’
/tmp/ccGXrSE5.o: In function `main':
**k... |
You have declaredibut haven't defined it, that's why the linker is complaining.
|
I've seen both full definitions ofstructs in headers and just declarations—is there any advantage to one method over the other?
If it makes a difference, I usually typedef a struct like so in the.h
```
typedef struct s s_t;
```
To be clear, the options are declaration in the header file and definition in the clas... |
Private structures for that file should go in the .c file, with a declaration in the .h file if they are used by any functions in the .h .
Public structures should go in the .h file.
|
I want to create an algorithm using genetic programming, based on symbolic regression.
I read some articles about that, some examples written on java or c++.
Maybe is more difficult because it isn't OOP, but is it possible to develop genetic programming in C?
What do you suggest to me to start programming? Any book... |
I've usedGAULin the past, and I'm fairly certain it's written to work with C. It did the job for me.
|
I am looking for a good library (preferably in C/C++) that can calculate the intersections between a line segment (ray) and a trimesh.
Thanks in advance for any answers!
|
CGALis probably overkill, but I suggest it just for reference. Thedocumentationis somewhat intimidating, butthis chaptercould be of interest for you.
|
I am revising some very old (10 years) C code. The code compiles on Unix/Mac with GCC and cross-compiles for Windows with MinGW. Currently there are TCHAR strings throughout. I'd like to get rid of the TCHAR and use a C++ string instead. Is it still necessary to use the Windows wide functions, or can I do everything n... |
Windows uses UTF16 still and most likely always will. You need to usewstringrather thanstringtherefore. Windows APIs don't offer support for UTF8 directly largely because Windows supported Unicode before UTF8 was invented.
It is thus rather painful to write Unicode code that will compile on both Windows and Unix plat... |
This has probably been asked to death around here, but I could never get to a final solution (probably for good cause).
Anyway, is there any way in Ubuntu (I use Ubuntu 11.04 with kernel 2.6.38-8) to detect if there is a headphone plugged in? Specifically, I'm searching for C/C++ solutions to poll my ALSA device to d... |
The jack detection API is (hereorhere):
```
snd_jack_new — Create a new jack
snd_jack_set_parent — Set the parent device for a jack
snd_jack_report — Report the current status of a jack
```
|
I going to split up the text
```
Central & Western - Water Street,6799,660,2780,1901,2624
Wan Chai - Hennessy,6505,766,1606,2071,2725
Wan Chai - Oi Kwan,6232,737,1919,2696,2651
Wan Chai - Canal Road,7607,982,2021,2913,3083
Wan Chai - Causeway Bay,6311,819,1387,2324,3275
Wan Chai - Tai Hang,6856,899,2148,1949,2725
Wan... |
Just remove the quotes from your expression (they are not needed):
```
"%[^,],%d,%d,%d,%d,%d"
```
|
I have been working on a VS 2005 project and have successfully generated an exe file which works fine on my system. However when I tried to run it on some other pc it didnt run. It throws up the error message "the system cannot run the specified program". Can someone tell me how to make my code immune to such message ... |
I have seen before exe created on Windows Sp1 not working on SP2 and problems such as that.Thisshould help you perhaps.
|
I'm looking for a PHP-like high level C utility library.
I've found the following libraries:
APR = Apache Portable RuntimeGLib (part of the GTK+ project)qlibciMatix' SFL = Standard Function Librarycbase
All of them looks good, but i'd like to know if there is a straight C port of some PHP functions.
My aim is to sp... |
There are many libraries for all kinds of things. If you want something with functions exactly like PHP's, you could try to adapt the PHP source code to your needs. You can find the standard built-in functions inext/standard/*.cin the source code directory.
(the result will likely be worthy of dr. Frankenstein's appr... |
I'm writing a simple shell in C and I want to implement the user input the same way the other shells do, or at least how bash does (never used others). If you enter a command with random whitespace then it can still run the command:
ex.
ls -1
Obviouslystrtok()wont work on this when sep... |
Youcanskip spaces while you're parsing your command:
```
while(*p==' '||*p=='\t') ++p;
```
|
```
struct file_operations hello_fops = {
owner: THIS_MODULE,
read: hello_read,
write: hello_write,
ioctl: hello_ioctl,
open: hello_open,
release: hello_release,
};
```
Here what is the meaning of : after struct field i.e owner:
Somewhere I 've also seen like .owner:=
Also how can I see what are the other available ... |
```
{.field=value}
```
is a C99-style initializer.
```
{field: value}
```
is a GCC-style initializer.
ownerhas nothing to do with permissions. Permissions are the normal file permissions, you may want to use anudevrule to set appropiate permissions. Anioctlcall will typically require additional permissions, depend... |
I come from a windows w/ visual-studio background for native development and I am now going to compile native code for use on android.
I am not sure how the unix-like libraries (.so?) work. Are they static (like a .lib on windows) or dynamically loaded like a DLL?
For example, in visual studio, I add the .lib file t... |
On Linux, the .so files are the equivalent(*) of the .dll files on Windows, in the sense that they are loaded dynamically to the executable when it is executed. Note however that you don't need a .lib file when linking your application. The linker will find the information directly in the .so file.
*: There are diffe... |
I've got an iphone project that I've added a .c file and corresponding .h file.
In my app delegate I do the normal #include "MyCfile.h".
But when I try to create a variable of type "MyCfile" it doesnt appear in the code hinting. It's almost like xcode doesnt know it's there.
What am I doing wrong?
|
Is there an actual class or struct named MyCfile ? Just having a source file by this name doesn't do anything; you didn't mention a class so I'm going to assume you just haven't defined one in that header file.
|
can anyone tell me what is wrong with this code:
```
CC = "C:\Program Files\Microsoft Visual Studio\VC98\Bin\CL.EXE"
CFLAGS = /nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"$(OBJ_PATH)\$(EXECUTABLE).pch" /YX /Fo"$(OBJ_PATH)\\" /Fd"$(OBJ_PATH)\\" /FD /GZ /c
$(OBJ_PATH)\%.obj : $(... |
The backslashes are interpreted as escapes by GNU make and disable the special meaning of %. Try doubling the backslashes or replacing them by forward slashes.
|
I am building C libraries that will be used by an android app(through either JNI or the NDK, I've never used the NDK though) and I am wondering what IDE/development environment is best to use? I've basically only used Visual Studio for native development and I'm not sure how to adapt to building .so libraries for use ... |
Generally, cygwin (i.e. command line) is used for building Android native code. But you can also try to use Eclipse for this purpose. It doesn't help very much but it highlights syntax and you don't have to switch to other apps to write code and build your app. You can read more about using Eclipse for C/C++ Android d... |
I've been reading about exporting a C++ class so that C can use it. I've followed this goodexamplefrom Parashift, and a question came out.
To hold the memory allocated to the C++ class, we define the following structure
```
typedef struct A A;
```
So thatA*can point to the address of the class A. My question is: do... |
No, you shouldn't usevoid*by this. A pointer to an incomplete typestruct Ais a much better technique. This avoids that you mix pointers to different opaque types by accident. If you'dtypedefit tovoidyou could assign a pointer of your opaque type to any other data pointer. Probably not what you want.
Using an incomple... |
```
struct dataStruct { const char* s; int num; };
struct Final_struct { int n; dataStruct a[]; };
```
Now the problem occurs when I try to initialize the Final_struct as followed:
```
const Final_struct Example[]= {
{100, { {"age", 20}, {"iq", 120}, {"bmi",26} } },
... |
dataStruct a[]defines the member of the struct as an array of size0. This is practically useless. You need to specify its size in the definition of thestructbecause the compiler needs to know the size of the entirestructin advance.
Or, you can simply declare the field asdataStruct *aand then the array itself will not... |
How can I do cursor control with ANSI using escape sequences using Turbo C? Here I've provided a code, but it's not yet working in my TurboC.
```
main()
{
while( getche() != '.' )
printf("\x1B[B");
}
```
|
Apart from the possibility that that output may be line buffered (meaning nothing may appear until you send a newline), you should probably also ensure thatANSI.SYSis loaded, since it's the device driver responsible for interpreting those sequences.
But I'm wonderingwhyyou're doing this. From memory (admittedly prett... |
This question already has answers here:Closed12 years ago.
Possible Duplicate:C: Where is union practically used?
I know the concept of union but I don't see the actual case in real world coding that I should use union data structure. I will be very appreciated if you guys can give me some examples or tutorials that... |
Imagine having astructthat keeps a value and the type of that value. When the type is set to a particular type, you would only need to use one of the members of theunionrather than waste space for three of them when you use only one simultaneously.
```
struct {
int type;
union {
int intval;
double dval;
... |
I have a Makefile where the first line is of the type:
```
all:client.so simulator
LD_PRELOAD=/path/to/shared/lib/client.so ./simulator
```
and the other lines to above follows
Now, I have another program say xyz.c whose executable is called from within simulator using execve().
How can I include the comp... |
Can't you just makealldepend on the executable for xyc as well? And then add targets to build that from xyc.c?
|
I've been looking everywhere and all I can find are tutorials on writing the shaders. None of them showed me how to incorporate them into my scene.
So essentially:
Given an hlsl shader, if I were to have a function called drawTexturedQuad() and I wanted the shader to be applied to the result, how exactly could I do ... |
ID3DXEffect providesBegin()andBeginPass()methods. Simply calldrawQuad()during that time. Any basic tutorial on shaders should show such a sample.
Just an additional note- if in doubt, askMSDN.
|
I have been messing around with ptrace and registers a lot lately and I was wondering if there is a difference between pt_regs and user_struct_regs as far as content goes. More specifically, do they both hold the same content(register values) but just have different named members to hold it.
I noticed that some archi... |
The format and layout of registers is highly architecture-specific. You have to read the definitions and comments in/usr/include/asm/user.hheader. (For linux; the exact location might differ from OS to OS -- read the relevant ptrace documentation.)
|
Closed.This question is seeking recommendations for books, tools, software libraries, and more. It does not meetStack Overflow guidelines. It is not currently accepting answers.We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answer... |
I worked on making something I'd be able to use and I've published it on github: it's unimaginably calledthreadpool.
|
I'd like to have my server determine the source IP and port of a client from a connected TCP socket. Since my clients are likely behind NAT's, I can't rely on being told by the client (in the protocol of the connection)... If this is possible, I'm going to need to implement it on both Windows and Linux... But an answe... |
Should work both in linux and windows:
```
struct sockaddr_in addr;
socklen_t len;
len = sizeof addr;
getpeername(clientSocket, (struct sockaddr*)&addr, &len);
printf("Remote IP address: %s\n", inet_ntoa(addr.sin_addr));
```
|
How to forcefully link all symbols of a static library to an application at link time in gcc?
I am trying to create an application by linking two static libraries. Both these libraries may have some symbols which may have the same name. I want to find all such symbols and rename them in one of the libraries.
But, I ... |
Could you just use thenmcommand (link) on each library?nmshould list all the symbols and then you can just compare the output ofnmfor each library.
|
I'm looking for classes like "File, Socket, String" wrapping the C (or C++) standard library functions and throwing exceptions in case of errors.
|
Maybe the question wasn't clear,
btw i've found this library is exactly what i was looking for:commonc++.
Edit:Better alternative still maintained.
|
I am porting an application from Tru64 to Linux and it uses PID_MAX defined in limits.h.
Linux doesn't have that define.
How do I find PID_MAX incwithout reading/proc/sys/kernel/pid_maxby hand?
Is there a library?
|
It's 32768 by default, you can read the value on your system in/proc/sys/kernel/pid_max.
And you can set the value higher on 64-bit systems (up to 222= 4,194,304) with:
```
echo 4194304 > /proc/sys/kernel/pid_max
```
Read more here:
http://www.cs.wisc.edu/condor/condorg/linux_scalability.html (via archive.org)
|
How to swap the following two hexadecimal numbers in c language? Eg:
input :0xabcdoutput:0xcdab
|
You can use something along the lines of:
```
#include <stdio.h>
int main (void) {
unsigned int from = 0xabcd;
unsigned int to = ((from & 0xff) << 8) | (from >> 8);
printf ("%04x\n", to);
return 0;
}
```
This swaps the two bytes around, giving you an output ofcdab.
|
A small piece of code:
```
void func()
{
const int BUF_SIZE = 5;
char scale[BUF_SIZE];
}
```
This code is built fine under C++, but under C I have an errors:
```
error C2057: expected constant expression
error C2466: cannot allocate an array of constant size 0
```
Why?
Compiler: Microsoft Visual C++ 2008
T... |
In C (all variants, I believe), aconstis, ironically, not aconstant expressionin C. In pre-C99, array lengths must be a constant expression.
However, C99 has the concept of "variable length arrays", so if you're compiling with a C99-compliant compiler, your code should be valid even thoughBUF_SIZEis not a constant ex... |
I'd like to have my server determine the source IP and port of a client from a connected TCP socket. Since my clients are likely behind NAT's, I can't rely on being told by the client (in the protocol of the connection)... If this is possible, I'm going to need to implement it on both Windows and Linux... But an answe... |
Should work both in linux and windows:
```
struct sockaddr_in addr;
socklen_t len;
len = sizeof addr;
getpeername(clientSocket, (struct sockaddr*)&addr, &len);
printf("Remote IP address: %s\n", inet_ntoa(addr.sin_addr));
```
|
How to forcefully link all symbols of a static library to an application at link time in gcc?
I am trying to create an application by linking two static libraries. Both these libraries may have some symbols which may have the same name. I want to find all such symbols and rename them in one of the libraries.
But, I ... |
Could you just use thenmcommand (link) on each library?nmshould list all the symbols and then you can just compare the output ofnmfor each library.
|
I'm looking for classes like "File, Socket, String" wrapping the C (or C++) standard library functions and throwing exceptions in case of errors.
|
Maybe the question wasn't clear,
btw i've found this library is exactly what i was looking for:commonc++.
Edit:Better alternative still maintained.
|
I am porting an application from Tru64 to Linux and it uses PID_MAX defined in limits.h.
Linux doesn't have that define.
How do I find PID_MAX incwithout reading/proc/sys/kernel/pid_maxby hand?
Is there a library?
|
It's 32768 by default, you can read the value on your system in/proc/sys/kernel/pid_max.
And you can set the value higher on 64-bit systems (up to 222= 4,194,304) with:
```
echo 4194304 > /proc/sys/kernel/pid_max
```
Read more here:
http://www.cs.wisc.edu/condor/condorg/linux_scalability.html (via archive.org)
|
How to swap the following two hexadecimal numbers in c language? Eg:
input :0xabcdoutput:0xcdab
|
You can use something along the lines of:
```
#include <stdio.h>
int main (void) {
unsigned int from = 0xabcd;
unsigned int to = ((from & 0xff) << 8) | (from >> 8);
printf ("%04x\n", to);
return 0;
}
```
This swaps the two bytes around, giving you an output ofcdab.
|
A small piece of code:
```
void func()
{
const int BUF_SIZE = 5;
char scale[BUF_SIZE];
}
```
This code is built fine under C++, but under C I have an errors:
```
error C2057: expected constant expression
error C2466: cannot allocate an array of constant size 0
```
Why?
Compiler: Microsoft Visual C++ 2008
T... |
In C (all variants, I believe), aconstis, ironically, not aconstant expressionin C. In pre-C99, array lengths must be a constant expression.
However, C99 has the concept of "variable length arrays", so if you're compiling with a C99-compliant compiler, your code should be valid even thoughBUF_SIZEis not a constant ex... |
I want to create a message server using epoll. Several devices will connect to the server and exchange simple text messages. I don't have that much experience with this and I will be very appreciated if you guys can provide me any references or tutorials related to this.
I would like to work with C. Thanks in advance... |
I would suggest you start by taking a lookhere, and keepingthisclose as a reference.
|
Is it safe when therequest_token.size()is larger thanLEN?
```
char dst[LEN];
memcpy(dst, request_token.c_str(), request_token.size());
```
|
No, it's not safe; you'll cause a buffer overflow. The reason is,memcpyhas no way to know the size of your target buffer, other than the size you pass in the third argument.
|
I am using opencv to process very large images (some times even more than 2500x2000). When I display such an image using a normal cvNamedWindow it occupies the whole screen and even I am unable to scroll down or sideways to see other parts. Is it possible to reduce the size of image only while displaying?
Note: the s... |
You have to use the flagCV_WINDOW_NORMALto alter this behavior. This flag will make the window manually-resizable.
```
cvNamedWindow(yourWindowName, CV_WINDOW_NORMAL);
```
|
Is detecting tabs same as detecting the spaces? i.e. for detecting a space, I would just compare the space character with its ascii number.
For a tab do I have to search for '\t' character in the file or there is some other way?
|
```
if('\t' == myChar)
```
This would work, and would be better than checking against 9 since 9 may not be a guaranteed value across all architectures.
|
How can I add a watchpoint in.gdbinitfor a specific memory location which is going to be allocated on the heap from within a shared object.so?
The following would work if the .so would be already loaded:
```
watch *((TOKEN*)0x084E4C40)
```
However I want to put this in .gdbinit, but that doesn't work, because it ha... |
You don't really need the symbol, only the size of the memory chunk you want to watch. Use this command
watch *(char(*)[NNN])0x084E4C40
whereNNNissizeof(TOKEN).
|
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.Closed12 years ago.
I'm currently delving into learning... |
Did not answer exactly what you asked,but ...
Tring to solve some Euler problems is a good way to familiar with the language features.
http://projecteuler.net/
|
I would like to add arp bindings into/proc/net/arpinC. Writing into file is not allowed, so trying to do it some other way. Any suggestions? I already know about net-tools, but havent tryed yet
|
You will need to use thenetlink protocolorlibnetlink. I would recommend looking at the source for thearpcommand to see exactly how it does it.
|
I'm a bit lost with time terminology.
I understand whatepochis and the difference betweenGMTandUTC.
However I'm a bit confused about the following notations:
calendar timelocal timewall time
How are these related to timezones and daylight savings?
P.S.Goodlink(thanks to @ZincX)
|
Calendar time is the time that has elapsed since the epoch (t-E).Local time is calendar time corrected for the timezone and DST.Wall time: I assume you meanwallclock time. This it the time elapsed since a process or job has started running.
RTFMtime(7),localtime(3),time(1).
|
The question is:
Suppose I use the function:
(* env) -> GetByteArrayRegion (env, array, 0, len, (jbyte *)buf);
In this case, a certain number of bytes written from the array to the buf or vice versa? Maybe a simple question, but I'm confused. Help, please:. In the documentation is not found.
|
`Get < PrimitiveTypeArray>ArrayRegion' is a family of functions that copies a region of a primitive array into a buffer. That's what the documentation says. It seems clear to me.
|
I have ac:\configfolder which contains several configuration files (config_x).
I would like to be able to choose one of them at random (the program is written in C).
The number of files may change in the future - so needs to be able to query for number of files in the folder.
How can it be done?
|
UseFindFirstFileandFindNextFileto build a list of the files in the folderGenerate a random number between 0 and the number of files and then pick that index from the list
MSDN hasan example on listing files.
|
I want to integrate a c language compiler in to java application to compile c sources without file creation (Like Java Compiler Api). Is there any c compiler that has entirely written in java?
|
You can check this link from Google CodeC compiler written in Java
and say congratz to the developer :) -it's not me :p-
Another option is this one:JCPP
|
When using GLib 1.2'sGHashTablewith theg_hash_table_foreach()method, is it safe to remove items using theg_hash_table_remove()method?
I know that Glib 2.0 provides theg_hash_table_foreach_steal()method, but we're stuck with 1.2 for our build at work.
|
Well it's not allowed in the current API, so I'd be really surprised if that functionality was there in 1.2.
|
I'm working on a big, old, project that is using autotools. I would like to switch one part of the project to C++ (from C).
How can I switch the compiler used for a part of the project? I don't like the idea of completely splitting the project into two parts. The directory has onlyMakefile.amand I suppose I should re... |
You must define output variable CXX in configure.ac (the simplest way is by using AC_PROG_CXX macro), then all files with appropriate suffixes (.cc, .cpp) will be compiled by C++ compiler.
|
Consider the following OpenMP for loop:
```
#pragma omp parallel for schedule(dynamic)
for (int i = 0; i < n; ++i)
{
//do something with i
}
```
Is it guaranteed that each OpenMP thread sees its i values in ascending order?
|
The order in which threads run is not guaranteed;the order in which a thread processes its own chunk is guaranteed.
|
If I Make A Program In C Without Including Windows.h Header File Will It Run On Linux.
I Am Making It In Code Blocks On Windows.
|
If you only use the Standard C Library you'll be fine. if you go includingio.handconio.hand other junk like that, then you won't be fine.
Obviously I am assuming you are not expecting a windows PE to run on linux (without WINE) or a linux ELF to run on windows (you have to recompile like @sehe suggests).
|
There is a native method from dll written in c which takes a parameter of type time_t.
Is it possible to use C# uint or ulong for this parameter?
|
I do not think I should say they are equivalent, but you can convertt_timetoDateTimein such a way:
```
int t= 1070390676; // value of time_t in an ordinary integer
System.DateTime dt= new System.DateTime(1970,1,1).AddSeconds(t);
```
And this example is fromHow can I convert date-time data in time_t to C# DateTime c... |
I can imagine static variablesvarinside a functionfuncto be named likevar@func,
what about global static and non-static variables?
|
Compilers don't need to uniquely name things with internal linkage, like static variables and functions. You can't access static objects outside the translation unit, so the linker doesn't need to get a name for them.
Global variables with external linkage don't usually have much mangling or decoration applied to the... |
The code is just very simple, yet I scratch my head at the results.
I am just playing pointer arithmetics and want to print out the array
but I get the numbers of the array plus 3 more. Where do those 3 extra come from ?
```
#include <stdio.h>
int my_array[] = {1,3,5,6,73,343,34};
int *pointer_numeros;
int main ... |
*pointer_numerosdoes not evaluate to false at the end of the array; it will carry on walking through memory until it hits an address whose contents are zero (but this isundefined behaviour).
You can terminate your array in a zero, as others have suggested. But in general, you will still have a problem: what if some ... |
I need to load an image into my program. I want to allow the user to browse for any image s/he wishes and open. I need a function which asks the user to browse and select the desired file and can generate a string containing the complete path of that particular file.
|
You don't say on which platform you are working.
If you are working on Windows, the fastest way is to use the OPENFILENAME structure with the GetOpenFileName function as shown in this example:http://msdn.microsoft.com/en-us/library/ms646829(v=vs.85).aspx#open_file. You can then use cvLoadImage with the lpstrFile memb... |
Closed.This question isoff-topic. It is not currently accepting answers.Want to improve this question?Update the questionso it'son-topicfor Stack Overflow.Closed12 years ago.Improve this question
Hi I dont know if this is the right place to ask... but could someone tell me if there is any open source operations manag... |
If by operations, you mean "automated deployment and maintenance of systems", perhaps you're looking for something likeOpscode and their Chef framework.I just happen to have heard of this one, probably there are many others.
|
Can somebody verify whether the functiongtk_combo_box_text_append()is available from 2.24 or 3? I was playing with it last night and I got undefined reference error to the specific function.
By the way, I did the test on Slackware64 13.37 on which I checked the version of gtk+2 is 2.24.4.
|
According todocumentationthere is no such function in 2.24. There is functiongtk_combo_box_text_append_textin both 2.24 and 3.
|
I am developing an Android application using NDK. The application blows up with "SIGSEGV" error which I believe a segmentation fault error.
I looked at my code and I think memcopy and memmove might cause this error. I was wondering if there is a safe way to call these functions.
Also please let me know any well desc... |
The rule with those 2 is that you use memcpy when you're copying a block of bytes from one place to another, and the source and destination don't overlap. If they do overlap, you have to use memmove. However, using them incorrectly results in corrupted data, not segfaults. Segfaults happen when you try to read or w... |
i'm facing a problem right now, i need to count the number of time a certain MxM matrix appears inside a NxN one (this one should be larger than the first one). Any hints on how to do this? I'm going to implement it in C and there is no option to change it.
Revision 1
Hi everyone, i would really like to say thank to... |
Hm, sounds like a 2-dimensional version of string matching. I wonder if there's a 2D version of Boyer-Moore?
A Boyer-Moore Approach for Two-Dimensional Matching
Ah, apparently there is. :-)
|
Is this code (simplified from a real project) correct? Will the message always print?
```
char *cp = NULL;
char **cpp = &cp;
if(*cpp == NULL) {
printf("I believe this will this always print. Does it?\n");
}
```
Thanks!
|
There is nothing wrong with the code you have shown. Yourchar **pointer is pointing to a valid variable, thus it's always proper to dereference it.
P.S. Yes, it will always print.
|
I'm having a seemingly silly problem with my gcc compiler. I have installed MinGW at location C:\MinGW... and I have added C:\MinGW\bin to my windows path. However, when I got to the command prompt and type gcc --version... it doesn't recognize it. I have to cd manually to the bin before it will recognize it.
When... |
How did you set the path? You should set it fromControl Panel->System->Advanced->Environment Variables. The change will affect newly opened command consoles only.
If it then does not work, in the console, when you enter the commandpathdoes the displayed path list include your path? Is it correct?
Are ther other GN... |
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.Closed12 years ago.
Here I have a pointer to the first ... |
```
vector = malloc(sizeof(struct vector_new))
vector->start = malloc(size);
vector->count = size;
```
I'm not sure exactly what you are asking for.
BTW, std::vector has a "used" size and a "allocated" size, a semantic which you do not reproduce here.
I also agree that you are unlikely to write this faster than std... |
i like to use a library or function in C which could perform the same function as performed bymeshgridin MATLAB.
looking for support.
|
I don't see why you need a function or library for this.
Thissays "[X,Y] = meshgrid(x,y) transforms the domain specified by vectors x and y into arrays X and Y, which can be used to evaluate functions of two variables"
If the vector is something like "a:b" then you can use aforstatement to create the appropriate mat... |
Can anyone tell me how i can give command line argument (int argc and char*argv[]) in turbo C compiler??
Thnx
|
Launch a command promptrun your executable. if it is abc.exe do :abc.exe argument1 argument2 argument3 . . . argumentn
In the codeargv[0]will containabc.exe,argv[1]will containargument1and so on.argcvalue would be the number of strings inargv
Sample
```
#include <stdio.h>
int main (int argc, char *argv[])
{
int ... |
This question already has answers here:Closed12 years ago.
Possible Duplicate:integer size in c depends on what?
Why is the size of an integer 2 bytes on a 16-bit compiler and 4 bytes on a 32-bit compiler? And also, how is it related to OS?
```
printf("%d", sizeof(int));//what will be o/p on windows 32bit Turboc 32... |
16 bit compilers are generally used for 16 bit hardware, where the natural size of an integer is 16 bits. The "int" type is intended to use the natural size of the hardware.
|
I want to create pkcs7 signed envelop having S/MIME format and also want to read it. The file extension ispk7.
How to do it with the OpenSSL library?
|
TheSMIME_read_PKCS7()andSMIME_write_PKCS7()functions can be used to convert an SMIME message into a PKCS7 structure and vice-versa.
You can usePKCS7_sign()/PKCS7_encrypt()to create PKCS7 structures, andPKCS7_verify()/PKCS7_decrypt()to consume them.
|
I would like to use XCode 4 as IDE for my C program.
I am using few libraries, which are not installed in system paths. Also, I am using external program for building (waf).
So, basically, I need XCode for everything, except building.
But I can't figure out how to tell XCode where my library include files are for i... |
In the build settings for the Target - look for theHEADER_SEARCH_PATHSsetting.
Have you added the library headers to the project? You can just add them by reference.
|
I have large C code base for a micro-controller. I am working on a task to check if all global variables are thread-safe or not.
We don't have threads, but we have interrupts (high priority interrupts can preempt low priority ones).
NOTE: I useSciTools Understandtool to make searching for global variables and their ... |
It seems there is no something ready which do this. I did a perl script which uses SciTools Understand APIs to get the shared global variables.
|
cppcheck has determined that the following statement produces a syntax error in sqlite3.c:
for(i=0; i<db->nDb; i++){
Full function:
```
SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3 *db){
int i;
Btree *p;
assert( sqlite3_mutex_held(db->mutex) );
for(i=0; i<db->nDb; i++){
p = db->aDb[i].pBt;
if( p... |
Looks like a false positive, however I can't reproduce it using Cppcheck 1.48 and C source code for SQLite 3.7.6.3.
If you're using different source or a different version, pleaselog it as a bug.
|
I am using gnu tool chain. How can I, at run time, find caller of a function? i.e for example function B() gets called by many functions using function pointers. Now, whenever B gets called, I want to print the callers name. I need this for debugging a certain issue.
|
If you're using GNU, you can use thebacktracefunctions. There's an example of the use on that man page.
|
I'm trying to match on a line ending with something like:
```
blocking=12345us
```
The pattern I tried to match with is:
```
char *pattern = "blocking=(\\d{1,})us";
```
I have tried it with only one blackslash just in case but still no luck.
If I change that line to:
```
char *pattern = "(.*)";
```
it matches f... |
Looking at thedocumentation for REs supported by regcompit would appear that\dis not supported - try:
```
char *pattern = "blocking=([0-9]){1,}us";
```
|
How can I print all global variables/local variables? Is that possible in gdb?
|
Typeinfo variablesto list "All global and static variable names" (huge list.
Typeinfo localsto list "Local variables of current stack frame" (names and values), including static variables in that function.
Typeinfo argsto list "Arguments of the current stack frame" (names and values).
|
I need to load an image into my program. I want to allow the user to browse for any image s/he wishes and open. I need a function which asks the user to browse and select the desired file and can generate a string containing the complete path of that particular file.
|
You don't say on which platform you are working.
If you are working on Windows, the fastest way is to use the OPENFILENAME structure with the GetOpenFileName function as shown in this example:http://msdn.microsoft.com/en-us/library/ms646829(v=vs.85).aspx#open_file. You can then use cvLoadImage with the lpstrFile memb... |
Closed.This question isoff-topic. It is not currently accepting answers.Want to improve this question?Update the questionso it'son-topicfor Stack Overflow.Closed12 years ago.Improve this question
Hi I dont know if this is the right place to ask... but could someone tell me if there is any open source operations manag... |
If by operations, you mean "automated deployment and maintenance of systems", perhaps you're looking for something likeOpscode and their Chef framework.I just happen to have heard of this one, probably there are many others.
|
Can somebody verify whether the functiongtk_combo_box_text_append()is available from 2.24 or 3? I was playing with it last night and I got undefined reference error to the specific function.
By the way, I did the test on Slackware64 13.37 on which I checked the version of gtk+2 is 2.24.4.
|
According todocumentationthere is no such function in 2.24. There is functiongtk_combo_box_text_append_textin both 2.24 and 3.
|
I am developing an Android application using NDK. The application blows up with "SIGSEGV" error which I believe a segmentation fault error.
I looked at my code and I think memcopy and memmove might cause this error. I was wondering if there is a safe way to call these functions.
Also please let me know any well desc... |
The rule with those 2 is that you use memcpy when you're copying a block of bytes from one place to another, and the source and destination don't overlap. If they do overlap, you have to use memmove. However, using them incorrectly results in corrupted data, not segfaults. Segfaults happen when you try to read or w... |
i'm facing a problem right now, i need to count the number of time a certain MxM matrix appears inside a NxN one (this one should be larger than the first one). Any hints on how to do this? I'm going to implement it in C and there is no option to change it.
Revision 1
Hi everyone, i would really like to say thank to... |
Hm, sounds like a 2-dimensional version of string matching. I wonder if there's a 2D version of Boyer-Moore?
A Boyer-Moore Approach for Two-Dimensional Matching
Ah, apparently there is. :-)
|
Is this code (simplified from a real project) correct? Will the message always print?
```
char *cp = NULL;
char **cpp = &cp;
if(*cpp == NULL) {
printf("I believe this will this always print. Does it?\n");
}
```
Thanks!
|
There is nothing wrong with the code you have shown. Yourchar **pointer is pointing to a valid variable, thus it's always proper to dereference it.
P.S. Yes, it will always print.
|
I'm having a seemingly silly problem with my gcc compiler. I have installed MinGW at location C:\MinGW... and I have added C:\MinGW\bin to my windows path. However, when I got to the command prompt and type gcc --version... it doesn't recognize it. I have to cd manually to the bin before it will recognize it.
When... |
How did you set the path? You should set it fromControl Panel->System->Advanced->Environment Variables. The change will affect newly opened command consoles only.
If it then does not work, in the console, when you enter the commandpathdoes the displayed path list include your path? Is it correct?
Are ther other GN... |
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.Closed12 years ago.
Here I have a pointer to the first ... |
```
vector = malloc(sizeof(struct vector_new))
vector->start = malloc(size);
vector->count = size;
```
I'm not sure exactly what you are asking for.
BTW, std::vector has a "used" size and a "allocated" size, a semantic which you do not reproduce here.
I also agree that you are unlikely to write this faster than std... |
i like to use a library or function in C which could perform the same function as performed bymeshgridin MATLAB.
looking for support.
|
I don't see why you need a function or library for this.
Thissays "[X,Y] = meshgrid(x,y) transforms the domain specified by vectors x and y into arrays X and Y, which can be used to evaluate functions of two variables"
If the vector is something like "a:b" then you can use aforstatement to create the appropriate mat... |
Can anyone tell me how i can give command line argument (int argc and char*argv[]) in turbo C compiler??
Thnx
|
Launch a command promptrun your executable. if it is abc.exe do :abc.exe argument1 argument2 argument3 . . . argumentn
In the codeargv[0]will containabc.exe,argv[1]will containargument1and so on.argcvalue would be the number of strings inargv
Sample
```
#include <stdio.h>
int main (int argc, char *argv[])
{
int ... |
This question already has answers here:Closed12 years ago.
Possible Duplicate:integer size in c depends on what?
Why is the size of an integer 2 bytes on a 16-bit compiler and 4 bytes on a 32-bit compiler? And also, how is it related to OS?
```
printf("%d", sizeof(int));//what will be o/p on windows 32bit Turboc 32... |
16 bit compilers are generally used for 16 bit hardware, where the natural size of an integer is 16 bits. The "int" type is intended to use the natural size of the hardware.
|
I want to create pkcs7 signed envelop having S/MIME format and also want to read it. The file extension ispk7.
How to do it with the OpenSSL library?
|
TheSMIME_read_PKCS7()andSMIME_write_PKCS7()functions can be used to convert an SMIME message into a PKCS7 structure and vice-versa.
You can usePKCS7_sign()/PKCS7_encrypt()to create PKCS7 structures, andPKCS7_verify()/PKCS7_decrypt()to consume them.
|
I would like to use XCode 4 as IDE for my C program.
I am using few libraries, which are not installed in system paths. Also, I am using external program for building (waf).
So, basically, I need XCode for everything, except building.
But I can't figure out how to tell XCode where my library include files are for i... |
In the build settings for the Target - look for theHEADER_SEARCH_PATHSsetting.
Have you added the library headers to the project? You can just add them by reference.
|
I have large C code base for a micro-controller. I am working on a task to check if all global variables are thread-safe or not.
We don't have threads, but we have interrupts (high priority interrupts can preempt low priority ones).
NOTE: I useSciTools Understandtool to make searching for global variables and their ... |
It seems there is no something ready which do this. I did a perl script which uses SciTools Understand APIs to get the shared global variables.
|
cppcheck has determined that the following statement produces a syntax error in sqlite3.c:
for(i=0; i<db->nDb; i++){
Full function:
```
SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3 *db){
int i;
Btree *p;
assert( sqlite3_mutex_held(db->mutex) );
for(i=0; i<db->nDb; i++){
p = db->aDb[i].pBt;
if( p... |
Looks like a false positive, however I can't reproduce it using Cppcheck 1.48 and C source code for SQLite 3.7.6.3.
If you're using different source or a different version, pleaselog it as a bug.
|
I am using gnu tool chain. How can I, at run time, find caller of a function? i.e for example function B() gets called by many functions using function pointers. Now, whenever B gets called, I want to print the callers name. I need this for debugging a certain issue.
|
If you're using GNU, you can use thebacktracefunctions. There's an example of the use on that man page.
|
I've been trying to figure out the best way to copy Linux ARP table into an array, I just need IP and MAC address. I have tried copying the /proc/net/arp file, but I do not find it the best way to do it, I read there might appear other entries beside ARP (IPv6 or sth). I am not sure! Is there any other option to get l... |
Theip neighbor listcommand fromiproute2uses anetlinksocket to query the kernel about the neighbour information.
It is recommended to use thelibnetlinkfrom the same iproute2 package to access this information.
|
I want to create an array of strings. The problem is that I want to be able to access the length of each string statically. I tried this:
```
char *a[] = {"foo", "foobar"};
```
The array works fine except that I want to know the length of each element statically.
I can't usesizeof(a[0])because it returns the size of... |
In short, no, not at compile-time (at least not for an arbitrary number of strings). There are various run-time initialization-like things you can do, as others have pointed out. And there are solutions for a fixed number of strings, as others have pointed out.
The type ofa[0]must be the same as that ofa[1](obviou... |
I am writing a multithreaded program where I want to handle a possibleCtrl-Ccommand from the user to terminate execution. As far as I know there is no guarantee that the main thread, which is able to cancel every working thread, will catch the signal. Is it, therefore, necessary to have a different signal handler to t... |
You can block signals from the calling thread with pthread_sigmask().
And, as the blocked signals are inherited to newly created threads, you can block SIGINT in the main thread, then launch your other threads, and then unblock it in the main thread, if that is preferable.
|
Is there a way or an API to install a font on the PC for every user, without logging off or restarting the PC?
|
See the MSDN document,Font Installation and Deletion, for full details. In summary:
Copy the font file to the fonts directory (%windir%\fonts).CallAddFontResource()to ensure the font is immediately available.Broadcast theWM_FONTCHANGEmessage.
Thanks to @Alex K for cleaning this up and adding the fine detail.
|
I want to write multiple structures to a single file. I used fwrite function and append mode. The writing process is done without any error. How can i read the specific structure. Which means if i want to read the third structure that i wrote to file, how can i do it. I used fseek function and try to find the third po... |
```
FILE * pFile;
pFile = fopen ( "example.txt" , "rb" );
fseek ( pFile , sizeof(MyStruct)*2 , SEEK_SET );
MyStruct str;
fread(&str, sizeof(MyStruct), 1, pFile,)
```
|
I have a struct :
```
struct ABC
{
int size;
int arr[15];
};
```
I know I cannot make 'int size' as 'const int size' so how can I keep the size member from being modified accidently/intentionally.Is there a way around in C?
Thanks.
|
It can be const:
```
struct ABC
{
const int size;
int arr[15];
};
int main() {
struct ABC a = {3, {1,2,3} }; // ok
a.size = 42; // error
}
```
|
Is there a way to convert a mpz_t variable to unsigned long long in C?How about the other way around,from ull to mpz_t?The gmp library doesn't support this as ull are part of C99.
I foundthisbut it's in c++,and I don't know how to code in c++.Thanks in advance.
|
Here are some functions for translating betweenunsigned long longandmpz_t. Note thatmpz2ullwill smash your stack if the number is too big to fit into anunsigned long long:
```
unsigned long long mpz2ull(mpz_t z)
{
unsigned long long result = 0;
mpz_export(&result, 0, -1, sizeof result, 0, 0, z);
return re... |
This seems ambiguous to me:
```
*p1->p2
*(p1->p2) or (*p1)->p2
*p1.a
*(p1.a) or (*p1).a
```
How does the compiler interpret such expressions?
|
It's all down tooperator precedence. Both->and.have higher precedence than*(in this context), so the two expressions are equivalent to:
```
*(p1->p2)
*(p1.a)
```
|
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.Closed12 years ago.
In C, why does
strtoul(argv[1])
j... |
Because you're calling it with the wrong number of arguments. Try
```
strtoul(argv[1], 0, 0);
```
Or if you want to enforce base-10 only:
```
strtoul(argv[1], 0, 10);
```
Be sure you included<stdlib.h>too!
|
I installed the gmp libraries in cygwin via its installer. I tried to compile a simple program with gcc.
```
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
int
main(void)
{
mpz_t test;
int i;
printf("enter number\n");
gmp_scanf("%Z",&test);
gmp_printf("test=%Z",test);
i=mpz_probab_... |
Are you asking gcc to link GMP?
i.e.:gcc -lgmp main.c ....
|
why should a code like this should provide a so high result when I give it the number 4293974227 (or higher)
```
int main (int argc, char *argv[])
{
unsigned long long int i;
unsigned long long int z = atoi(argv[1]);
unsigned long long int tmp1 = z;
unsigned long long int *numbers = malloc (sizeof (unsigned lon... |
atoi()returnsint. If you need larger numbers, trystrtol(),strtoll(), or their relatives.
|
Why does
```
char line[10] = "1234";
```
work fine but
```
char line[10];
line = "1234";
```
throws an
```
error: incompatible types in assignment
```
error?
|
Arrays are not pointers. In your second example,lineis a non-modifiable lvalue, but more importantly, no matter what you put on the righthand side, it can't have typechar [10](because arrays decay to pointers in non-lvalue context) and thus the types can never match.
For what it's worth, a string literal has typechar... |
This seems ambiguous to me:
```
*p1->p2
*(p1->p2) or (*p1)->p2
*p1.a
*(p1.a) or (*p1).a
```
How does the compiler interpret such expressions?
|
It's all down tooperator precedence. Both->and.have higher precedence than*(in this context), so the two expressions are equivalent to:
```
*(p1->p2)
*(p1.a)
```
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.