question
stringlengths 24
425
| answer
stringlengths 5
405
|
---|---|
This question already has answers here:Closed12 years ago.
Possible Duplicate:Why is FILE all-caps as in FILE*?
Why is the standard libraryFILEtype written uppercase ?Is it because of its opaque nature ?
Thank you.
| If you look at the naming convention used in C, upper case is typically used for preprocessor macros. My guess is that it originally was implemented as a macro expanding to the concrete type used by the library implementation.
|
Is there a portable library to watch for filesystem changes without polling?
I know there is
inotifyfor Linuxsolution for osxFindFirstChangeNotificationfor WindowsNIO.2for JavaSystem.IO.FileSystemWatcherfor .NET
but i have not found any portable wrapper for those.
Is there a portable wrapper for Linux, Windows and OS X or a subset of those?
| QFileSystemWatcher-- Qt is very cross-platform.
|
Is there a way using c to save a retrieved webpage as an opera web document(.mht)? I can retrieve the page and save as html, but is there a way to convert it into this format?
| Did you look into theChilkat MHT library?
|
This question already has answers here:Closed12 years ago.
Possible Duplicate:Why is FILE all-caps as in FILE*?
Why is the standard libraryFILEtype written uppercase ?Is it because of its opaque nature ?
Thank you.
| If you look at the naming convention used in C, upper case is typically used for preprocessor macros. My guess is that it originally was implemented as a macro expanding to the concrete type used by the library implementation.
|
Is there a portable library to watch for filesystem changes without polling?
I know there is
inotifyfor Linuxsolution for osxFindFirstChangeNotificationfor WindowsNIO.2for JavaSystem.IO.FileSystemWatcherfor .NET
but i have not found any portable wrapper for those.
Is there a portable wrapper for Linux, Windows and OS X or a subset of those?
| QFileSystemWatcher-- Qt is very cross-platform.
|
My teams C-code guidelines write that it'd be better to place a '<' in a comment like shown below:
```
#define MAX_PACK_ITEM_NUM 50 /**< max number of item */
```
I wonder, what is the real use of this '<' ?
| It's a way fordoxygento generate documentation for members of a file/struct/union/class/enum. By using that marker, you can put comments after each member, leading to less clutter. You can read more about ithere.
|
Imagine this code:
```
int foo() {
return foo();
}
```
The compiler can optimize this. Can I force the compiler to use a new stack frame for foo, instead of using the same stack frame (per case, so disabling optimization completely doesn't count)?
| Yes, with-fno-optimize-sibling-callsoption.
|
I am trying to understand thesigsetjmp()andsiglongjmp()functions. The man pages state thatsigsetjmp()saves the context andsiglongjmp()restores the context. My question is, will they take care of stack pointer and program counter values as well?
Any links to extra resources are welcome.
| The stack pointer and program counter are both parts of the context (which you can think of as being, essentially, the state of the CPU registers).
|
Can anyone explain the implementation/algo that was used in rewind function? or is it possible to implement rewind function using lseek()?
| Here's a quote from a reference:
A call to rewind is equivalent to:fseek ( stream , 0L , SEEK_SET );except that, unlike fseek, rewind clears the error indicator.
http://www.cplusplus.com/reference/clibrary/cstdio/rewind/
|
I need to handle unicode strings in C. I have heard that ICU is the appropriate set of libraries to use but I am not having any luck getting started.
So my question: Can anyone provide a link to a good beginners tutorial on using unicode strings with ICU in C
P.S. I have installed libicu44 (under Ubuntu 11.04).
| ICU Reference Documentation
Tutorial
|
I'm beginner in C.
I have an char array in this format for example "12 23 45 9".
How to convert it in int array {12,23,45,9}?
Thanks in advance.
| Usesscanf, orstrtolin a loop.
|
see i want to count total no of code line, comment line in my whole project so is there any command or script inlinuxmachine for that purpose.
Is there any script for counting no of code in particular directory?
NOTE : my code is written in c langauge
| UseCLOC.
|
How could one initialize and set an array at the same time?
I'm looking for something equivalent to this:
```
int mat[2][2]={{1,1},{1,0}};
```
in mpz_t.
Cheers.
| mpz_t is more or less opaque to you, and it requires function calls to initialize.
So you can't initialize it with a C initializer.
|
Is it possible to useIntel C++compiler (icc) in Eclipse (CDT) on Windows? How?
| For what I could read inthis forum"no such integration is currently
supplied in the Windows environment for the Intel C++ compiler".
Alternatively, there is MinGW, a free tool for developing Microsoft applications and it gives access to the functionality of the Microsoft C runtime.
Seeherehow to set it up with Eclipse CDT.
You can also download MinGWhere.
|
Suppose some memory location 0xF0000 contains four character string"four".
so is this valid:
```
char *mem = (char*) 0xF0000;
```
and then is mem[0] == 'f' ?
| Yes it is valid if 0xF0000 is the starting address of the four character string "four"
|
Suppose some memory location 0xF0000 contains four character string"four".
so is this valid:
```
char *mem = (char*) 0xF0000;
```
and then is mem[0] == 'f' ?
| Yes it is valid if 0xF0000 is the starting address of the four character string "four"
|
I'm working on a CGI application written using C++ with the C MySQL adapter. I'm trying to run a query on two databases, so I want to connect to a MySQL server without choosing a default database. Is this possible? I'm usingmysql_real_connect().
| mysql_real_connect()can take aNULLparameter for the database paramter, and this selects the default. Just ensure that the user has no default database set.
|
I have now admitted defeat that you cannot use/build a good audio pitch function without using the NDK. Now my question is does anyone know of any good pitch changing code either in a library or some source code for the NDK?
| You could have a look at the MicDroid app that does auto-tune, sources available on GitHub:https://github.com/intervigilium/MicDroid
some more info here:
http://forum.xda-developers.com/showthread.php?t=721388
|
Is there a library for creating zip files (thezip file formatnot gzip or any other compression format) on-the-fly (so I can start sending the file while it is compressing) for very large files (4 Gb and above).
The compression ratio does not matter much (mostly media files).
The library has to have a c-interface and work on Debian and OSX.
| libarchive supports any format you want, on the fly and even in-memory files.
|
Say I have a program where the value of an integerishould never be negative. Is there a way I can insert a globalassert(i>=0)such that wheneveribecomes negative an error is reported. This can be very useful while debugging. I don't want to put an assert everywhere the value ofiis manipulated.
| No.
Your debugger might have this sort of facility, though. For instance, GDB haswatchpoints.
|
Any given point of time, how can i get the memory size utilized by each thread?
| If all you want is aheap profilerconsider Google performance tools with their own allocator TCMalloc.
http://code.google.com/p/google-perftools/
An alternative high performance allocator is jemalloc which provides statistics reporting including per-thread cache bin details withmalloc_stats_print()
http://www.canonware.com/jemalloc/index.html
|
I'm using those imports
```
#include <stdio.h>
#include <math.h>
```
and I'm gettingundefined reference to `round'at this line:
```
double res = round(atof(nextVal));
```
nextValis a double value read from a file.
I'm using Eclipse INDIGO.
| In command line, you must specify-lmoption to gcc to link the math lib. You have to find how to do so in eclipse.
|
Is it possible to create an array of arrays in c
Thank you.
| It's the same as for example in PHP:
```
int arrayInArray[10][50];
```
You read data out of it with:
```
printf("%d", arrayInArray[3][37]);
```
|
Does Macports have Ch and Cint (C interactive interpreters) as available ports? I can't seem to find them through port search.
Failing which, can anyone recommend what is the easiest way to install either Ch or Cint on Mac OS X?
| There is an effort by CERN developers to port their Cint to Clang: nicely namedClint.
Although I think CINT works fine on Mac: seeherefor build/install instructions
|
Title is pretty much self-explanatory. I googled on the web and SO, and not found a satisfactory enough answer. Example:
```
FILE* oneFile = fopen( file, someflags);
FILE* sameFile = fopen( file, someflags);
```
| C has nothing to do with it. It's all about your operating system underneath. C has no opinion.
|
I'm trying to establish whether Visual C++ 2008 or 2010 supports theloop unswitching compiler optimization. I know that gcc supports it.
| AFAIK, "No":
http://cboard.cprogramming.com/c-programming/126756-lack-compiler-loop-optimization-loop-unswitching.html
Your mileage might vary, depending on:
Whether or not you have the latest compiler (MSVS 2010)Whether or not you've purchased MSVS Professional or higher
|
Does Macports have Ch and Cint (C interactive interpreters) as available ports? I can't seem to find them through port search.
Failing which, can anyone recommend what is the easiest way to install either Ch or Cint on Mac OS X?
| There is an effort by CERN developers to port their Cint to Clang: nicely namedClint.
Although I think CINT works fine on Mac: seeherefor build/install instructions
|
Title is pretty much self-explanatory. I googled on the web and SO, and not found a satisfactory enough answer. Example:
```
FILE* oneFile = fopen( file, someflags);
FILE* sameFile = fopen( file, someflags);
```
| C has nothing to do with it. It's all about your operating system underneath. C has no opinion.
|
Just to make sure sure, one can call select on a Unix Domain socket. Correct? Also one can mix different types of sockets in a select statement. Is that correct?
| Yes, that is correct. The only type of file descriptor you should not put in aselectcall is a regular file, because regular files arealwaysconsidered ready, even if reading from them would block.
|
There should be something elegant in Linux API/POSIX to extract base file name from full path
| Seechar *basename(char *path).
Or run the command "man 3 basename" on your target UNIX/POSIX system.
|
Is it possible to Convert Int to Hexdecimal without using 'printf'?
Best if the all the value are placed in the variable itself and some sample code with explanation.
| The decimal and hexadecimal systems are just ways of expressing the value of the int. In a way "it is already a hexadecimal".
|
Could you please make it clear what the difference is betweenunsignedandunsigned int? Maybe some example code would be helpful.
| unsignedis a modifier which can apply to any integral type (char,short,int,long, etc.) but on its own it is identical tounsigned int.
|
Just to make sure sure, one can call select on a Unix Domain socket. Correct? Also one can mix different types of sockets in a select statement. Is that correct?
| Yes, that is correct. The only type of file descriptor you should not put in aselectcall is a regular file, because regular files arealwaysconsidered ready, even if reading from them would block.
|
There should be something elegant in Linux API/POSIX to extract base file name from full path
| Seechar *basename(char *path).
Or run the command "man 3 basename" on your target UNIX/POSIX system.
|
Is it possible to Convert Int to Hexdecimal without using 'printf'?
Best if the all the value are placed in the variable itself and some sample code with explanation.
| The decimal and hexadecimal systems are just ways of expressing the value of the int. In a way "it is already a hexadecimal".
|
There should be something elegant in Linux API/POSIX to extract base file name from full path
| Seechar *basename(char *path).
Or run the command "man 3 basename" on your target UNIX/POSIX system.
|
Is it possible to Convert Int to Hexdecimal without using 'printf'?
Best if the all the value are placed in the variable itself and some sample code with explanation.
| The decimal and hexadecimal systems are just ways of expressing the value of the int. In a way "it is already a hexadecimal".
|
Could you please make it clear what the difference is betweenunsignedandunsigned int? Maybe some example code would be helpful.
| unsignedis a modifier which can apply to any integral type (char,short,int,long, etc.) but on its own it is identical tounsigned int.
|
When I want to print a hexadecimal value of an integer using printf in C, I use the following statement :printf ("\n X = 0x%x \n",x);Here I assume the following declaration :int x = -1
Now this printsOxffffffff. I would like to see the output as 0xFFFFFFFF (all Tall Letters). Which format specifier will help me achieve that?
| printf ("\n X = 0x%X \n",x);
|
When I want to print a hexadecimal value of an integer using printf in C, I use the following statement :printf ("\n X = 0x%x \n",x);Here I assume the following declaration :int x = -1
Now this printsOxffffffff. I would like to see the output as 0xFFFFFFFF (all Tall Letters). Which format specifier will help me achieve that?
| printf ("\n X = 0x%X \n",x);
|
How can I add a speciific directory to the search path using the C API? And a related question: will the changes be local to the application, or is the search path global?
| UsePySys_GetObject("path")to retrievesys.path, then manipulate it as you wouldany other sequenceorlist. Changes will be local to the Python interpreter/VM.
|
i am trying to open a file in append mode using open() api call , however following code is not working ! Its not writing anything to file! here is my code :
| O_APPENDis not a mode by itself; it's a flag. Since the value ofO_RDONLYis 0, it's like you're trying to open the file read-only but for append, which is nonsense. UseO_WRONLY|O_APPENDorO_RDWR|O_APPEND.
|
I try to use erlang nif,
I made:
```
#include <erl_nif.h>
```
But get error:
fatal error: erl_nif.h: No such file or directory
Where can i find it? I have installed erlang R14B (erts-5.8.1)
OS Arch linux.
Thank you.
| Compile with-I/usr/lib/erlang/erts-5.8.1/include, if that's whereerl_nif.his.
|
i am trying to open a file in append mode using open() api call , however following code is not working ! Its not writing anything to file! here is my code :
| O_APPENDis not a mode by itself; it's a flag. Since the value ofO_RDONLYis 0, it's like you're trying to open the file read-only but for append, which is nonsense. UseO_WRONLY|O_APPENDorO_RDWR|O_APPEND.
|
I try to use erlang nif,
I made:
```
#include <erl_nif.h>
```
But get error:
fatal error: erl_nif.h: No such file or directory
Where can i find it? I have installed erlang R14B (erts-5.8.1)
OS Arch linux.
Thank you.
| Compile with-I/usr/lib/erlang/erts-5.8.1/include, if that's whereerl_nif.his.
|
I want to write some straight C code that uses some Foundation types. For now, I want to use NSInteger, NSUInteger, and NSRange; I can imagine wanting others later. Is there a header somewhere I can import that will get me these types without causing trouble in a straight C file?
| Not Foundation, but you can use Core Foundation (<CoreFoundation/CoreFoundation.h>or more specificallyCFBase.h), and the equivalent typesCFIndex,CFRange, etc.
|
I'm writing a multithreaded server using Ptrheads and I want to trace the execution of individual threads.
What would be a good tracing library for this?
| cTraceis an good option.
|
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.
Which is executes faster?
1:
```
n = n << 1;
```
2:
```
n = n + n;
```
| Any good compiler will end up making them both the same, so I can't imagine it matters.
|
I am in the directory/home/destinationI need to go back to the/homedirectory. Any ideas on how to implement this using a C-program?
| A program can only changeits own environment. Thus, the program canchdirbut it will not change the current directory of the parent. That's whycdcan't be implemented as an external command.
|
I would like to put the number given bysystem("stat -f %g /dev/console")in a variable (working in Xcode using C). How is this best achieved?
| I'd rather use thestatfunction :
```
struct stat file_details;
stat("/dev/console", &file_details);
printf("group id : %ld\n", (long) file_details.st_gid);
```
|
I have a very quick question to which I havn't found an answer for.
Are there any major platforms (Windows, MacOS, unix, linux, Android, iOS, etc....) out there that supports C but not C++?
Thanks
| C and C++ are not operating system dependant. If there is a compiler that can compile the C/C++ code to execute not he current CPU. All is good.
|
i have a string like this..
/home/Abcd/Pradeep/Jack.sh
/home/Abcd/Pradeep/Paul/Kill.sh
I need to take Jack.sh and Kill.sh alone from these strings. there can be many / in the string.
How to do this using strtok ?
| You don't needstrtokfor this. Just usestrrchrto find the last'/'character. Your filename starts one character after that.
|
I am in the directory/home/destinationI need to go back to the/homedirectory. Any ideas on how to implement this using a C-program?
| A program can only changeits own environment. Thus, the program canchdirbut it will not change the current directory of the parent. That's whycdcan't be implemented as an external command.
|
I would like to put the number given bysystem("stat -f %g /dev/console")in a variable (working in Xcode using C). How is this best achieved?
| I'd rather use thestatfunction :
```
struct stat file_details;
stat("/dev/console", &file_details);
printf("group id : %ld\n", (long) file_details.st_gid);
```
|
Is there an algorithm that can be use to subtract 1 from a number using only increments (++in C) and left bitwise shifts (<<in C) ?
EDIT: I am using type unsigned char
Thanks in advance
| You can do it with just the++operator. Loop forUCHAR_MAXiterations. Quite inefficient though:
```
unsigned char c = 42;
unsigned char i = 0;
while (++i)
{
++c;
}
// c is now equal to 41
```
LIVE DEMO
|
Ok, this was a bit too much for me. How do you read these declarations?
```
char *(*(**myCBT[][10])())[];
```
Please note: I'm not specifically asking for this example but for a general rule of thumb if a beginner like me faces a tough puzzle like this.
| Use David Anderson'sClock wise spiral rulefor reading such notations.
|
A compiler checks the syntax of source code from the text file. Why is it necessary to save it with an extension.cor.cpp?
I tried this on gcc but it does not compile a file with an extension other than.cand.cpp!!
| GCC (you name it on your tags) checks the file extension, if you do not specify a language with the-xoption.
If the extension is not recognized, the file is passed directly to the linker.
|
In scanf space and \n is delimiter for the character i/p.
The below program accepts only two input.
I could not understand why does it accept two input.Please explain about this behaviour.
```
char a,b,c;
scanf("%c%c%c",&a,&b,&c);
printf("%c%c%c",a,b,c);
return 0;
```
| Itdoesaccept 3 inputs if you don't put spaces between the input characters.
If you want to allow space(s) between inputs usescanf("%c %c %c",&a,&b,&c);.
|
Is there a way to traverse character by character or extract a single character from char* in C?
Consider the following code. Now which is the best way to get individual characters?
Suggest me a method without using any string functions.
```
char *a = "STRING";
```
| Another way:
```
char * i;
for (i=a; *i; i++) {
// i points successively to a[0], a[1], ... until a '\0' is observed.
}
```
|
Is there a way to traverse character by character or extract a single character from char* in C?
Consider the following code. Now which is the best way to get individual characters?
Suggest me a method without using any string functions.
```
char *a = "STRING";
```
| Another way:
```
char * i;
for (i=a; *i; i++) {
// i points successively to a[0], a[1], ... until a '\0' is observed.
}
```
|
Is there a way to traverse character by character or extract a single character from char* in C?
Consider the following code. Now which is the best way to get individual characters?
Suggest me a method without using any string functions.
```
char *a = "STRING";
```
| Another way:
```
char * i;
for (i=a; *i; i++) {
// i points successively to a[0], a[1], ... until a '\0' is observed.
}
```
|
I would like to Monitor the creation of windows (HWND) in C.
I'd like to know if there's some kind of event that the WINAPI provides to handle the creation of a window.
| If you are concerned only with top-level windows, you can useSetWindowHookExto register aShellProcand watch forHSHELL_WINDOWCREATED. If you need notification of the creation ofanywindow, you can use aCallWndProcand watch forWM_CREATEmessages.
|
I need to see if mystringmatches "hello X" where X is anyint.
Basically I want to catch if its "hello 1" or "hello 100".
How best can I do it?
Edit 0
Thanks Andrea Bergia.
I am using your code like this:
```
int dummy;
if (sscanf(string, "hello %d", &dummy))
/* matched */
```
| ```
int dummy;
int n = sscanf(string, "hello %d", &dummy);
if (n == 1) {
// Matched
}
```
|
I want to write a program in C# that uses a library to parse C source files, and provides me with a data structure containing all the functions and parameters associated found in it.
I don't need to know what is actually inside the function or anything else for that matter.
What would be a good library to do that?
| ANTLR can do what you'd like. It has a C preprocessor and ANSI C grammar.
(http://www.antlr.org/grammar/list)
|
I've seen many times code like this:
```
void func(){
#define a ...
...
#undef a
}
```
Is the#undefnecessary at all?
| It is not necessary, but the scope of a#defineis global after the line it was defined. It will not obey the function scope, if you are thinking it will.
|
what does this regex match?
How can I use this regex in C?
I am getting error if I do:
```
if (regcomp(®, "/[^\\]\]/", REG_EXTENDED | REG_ICASE) != 0)
```
error:
```
warning: unknown escape sequence '\]'
```
Thanks in advance.
| I think you need to escape your backslashes:
```
from "/[^\\]\]/" to "/[^\\\\]\\]/"
```
|
my string looks like this:
```
abcd "efgh [data\]" pqrl 12fgd]
```
I want to parse till ']' which is not proceeded by a backslash '\'
Can I do it withstrtok_r? If not than how should I do it?
| You could do it withstrchr. Here is how I would try to do it (untested):
```
p = str;
while ((p = strchr(p, ']')) {
if (p > str && *(p-1) != '\')
/* This is it. */
```
|
what is the purpose of signed char if both char and signed char ranges from -127 - 127?
what is the place where we use signed char instead of just char?
| unsigned charis unsigned.signed charis signed.charmay be unsignedorsigned depending on your platform.
Usesigned charwhen you definitely want signedness.
Possibly related:What does it mean for a char to be signed?
|
In linux using gcc when I write a loop like this
while(1 || 0)
It enters the loop but when I write the loop like this
while(0 || 1)
it doesn't enter the loop. What is the differrence?
| There is no any difference. Execution should enter the loop in both expressions.
|
I am trying to get total and if possible free memory of the system by C. It should be system-independent.
To initiate the discussion I can suggest getpagesize() method to get page-size. Anyone can help about number of memory pages would be good.
| There isn't a system independent way of doing this because it is obviously system dependent!
|
I am trying to parse through an array for a char and delete everything after that. I did write the code to find the location of the char search in the array. How to delete the remaining part of the array after the identified location. Thank you
| You can usememset:
```
memset(&arr[current_location], 0, sizeof(arr) - current_location);
```
To set all bytes inarraftercurrent_locationcontain0
|
I have a struct of values for a date.
```
struct date
{
int day;
int month;
int year;
};
```
Are there any libraries for C for quick and easy date validation.
| The standard C library functionmktime()will convert year/month/day (really a fullstruct tm) to atime_t, and tell you if something went wrong.
|
```
#include<stdio.h>
main()
{
int i;
char c;
for (i=0;i<5;i++){
scanf("%d",&c);
printf("%d",i);
}
printf("\n");
}
```
I thought it will print 0 1 2 3 4 but it didn't.
What's the reason of the strange output?
| Undefined Behaviour.
You're attempting to read anint(the"%d"in the scanf call) into an object of typechar(thec). Don't do that!
|
I am trying to parse through an array for a char and delete everything after that. I did write the code to find the location of the char search in the array. How to delete the remaining part of the array after the identified location. Thank you
| You can usememset:
```
memset(&arr[current_location], 0, sizeof(arr) - current_location);
```
To set all bytes inarraftercurrent_locationcontain0
|
I have a struct of values for a date.
```
struct date
{
int day;
int month;
int year;
};
```
Are there any libraries for C for quick and easy date validation.
| The standard C library functionmktime()will convert year/month/day (really a fullstruct tm) to atime_t, and tell you if something went wrong.
|
Is it possible to runscanfon input that it is not STDIN? What I mean is if I have astring="hello 1 2 3", can I run scanf on it to extract the string and three integers?
Is there another function that can do this?
| sscanfon a string (infohere)
fscanfon a file (infohere)
similarlysprintfandfprintfto write to a string/file.
|
I want to make sure that the project is configured entirely for C(NOT C++). I cannot find any accurate walk through for doing this. I am open to usingEclipse, except that it does not create a working project out of the box (which makes no sense...).
| Add/Tcas a command line option.
|
I have this structure:
```
typedef struct
{
int data[10];
} small_structure;
```
and this code:
```
small_structure *s_struct;
void * chunk;
chunk = malloc(1000);
s_struct = chunk;
```
Is it ok to do something like this? Ignore the fact that this is wasting memory.
| Yes, it is always legal to allocate more memory than you need, so long as that much memory is available.
|
any Idea how I could have the follow code output text with a transparent background?
```
SDL_Color co = {tp->col.r, tp->col.g, tp->col.b,tp->col.a};
SDL_Color bco = {255, 0, 255,1};
ts = TTF_RenderText_Shaded(tp->font, text.c_str(),co,bco);
```
| TTF_RenderText_Shadeddoesn't allow for transparent backgrounds (as it uses 8bit color), you want to useTTF_RenderText_Blended, seethis.
|
I wrote a program, that uses a shared library installed on my system. This library is seldom installed on other systems. How do I compile my program so that the library doesn't need to be installed on other systems? I have the source code for the library available. What's the best way?
The other systems of course have the same architecture and OS.
| Compile it as a static library and link that into the executable.
|
Does anyone know how to obtain lint for Mac, Windows, and Linux?sudo port install lintcan't find it.
| I've only seen lint for BSD. There'ssplint, however, a GPL lint rewrite, and it's available on most Linux distributions.
|
I've been looking throughctagsman pages but I haven't found anything that will tell ctags to only record prototypes forc99 header files.
Essentially, I have header files for bothCandC++files, but I only want those that correspond to c99 files (ie: noclassstuff) to be outputted.
| ctagshas the option--languagethat can force it to interpret files as being of a specific type.
|
I would like to organize better the following twoifstatements:
```
if(A || B){
do stuff...
}
if(A && ! B){
do other stuff...
}
```
Is there a better way?
EDIT:!beforeBon second statement, sorry...
| ```
if( A || B ) {
do some stuff;
if( !B ) {
do other stuff;
}
}
```
But the benefits depend on the usage, it could be harder to understand this version.
|
Consider:
```
#include <stdio.h>
int f() {
return 20;
}
int main() {
void (*blah)() = f;
printf("%d\n",*((int *)blah())()); // Error is here! I need help!
return 0;
}
```
I want to cast 'blah' back to (int *) so that I can use it as a function to return 20 in theprintfstatement, but it doesn't seem to work. How can I fix it?
| This might fix it:
```
printf("%d\n", ((int (*)())blah)() );
```
|
I am trying to scan in 1-3 words from the user into a string. However, Only the first word will scan.
| ```
scanf("%s", &area ) ;
```
scanfstops reading from the stream when a space is encountered. You need to usegetlineinstead.
|
How do I use the Python C-API to check if a PyObject* points to the type numpy.uint8 etc?
(Note that I want to check if the PyObject* points to the type numpy.uint8, not if it points to an instance of the type numpy.uint8.)
| You can usePyType_IsSubtype(child, parent)to see if the child type inherits the parent, but it operates onPyTypeObject*, notPyObject*.
|
While I know what the Unix system callbrkand functionsbrkdo, I have no idea what they stand for. Can anyone enlighten me?
| It comes from "break value".
I quote:
"The change is made by resetting the process's break value and allocating the appropriate amount of space. The break value is the address of the first location beyond the end of the data segment."
(source:http://www.s-gms.ms.edus.si/cgi-bin/man-cgi?brk+2)
|
What's a computationally sane way to, given a natural numbern, generate a random number that is relatively prime ton?
I'm willing to sacrifice some randomness and coverage of all possibilities for speed. That is, if I only ever hit perhaps 75% of the possible (smaller) relative primes, that's fine.
| "I'm willing to sacrifice randomness and coverage of all possibilities for speed."
Given n, select n+1.
You're going to need to be more specific.
|
I have a gamepad and i want to use the buttons on the joystick to interact with my program. I have been searching for a while now for any solutions and i cant find any. I have the device id and the vendor id are there any good example as to how i can accomplish this?
| You might want to look intolibusb, a C library for accessing USB devices. It is available on multiple platforms.
|
I have: Windows OS and installed Mingw.
I need: API to make console applications.
I only know cstdio functions, but I want more powerful interface to control input/output.
Any suggestions?
Thx.
| MSDN has information on all of the Win32 nativeconsole functions. Obviously, code that uses this API will not be portable.
|
Why does the following print1. I was expecting it to print the address of the function pointer.
```
#include <stdio.h>
int main(main) {
printf("%i",main);
return 0;
}
```
| Pointers must be printed with%p. Anyway here there's an "aliasing" problem, rather odd but that's it: main gets the value of the first argument to function main that is, what usually is called "argc". if you call it with more arguments, you should see bigger number.
|
I'm trying to do it this way:
```
int (*p)(void);
int *i;
...
p = (int *(void))i;
```
But it's causing syntax error:
```
error: cast specifies function type
```
What's wrong here?
| You should respect error in this case. You must not convert a pointer to function to an int pointer or other way around. That might result in undefined behavior.
If you insist then, syntax should be:
```
p = (int (*)(void))i;
```
|
I'm trying to do it this way:
```
int (*p)(void);
int *i;
...
p = (int *(void))i;
```
But it's causing syntax error:
```
error: cast specifies function type
```
What's wrong here?
| You should respect error in this case. You must not convert a pointer to function to an int pointer or other way around. That might result in undefined behavior.
If you insist then, syntax should be:
```
p = (int (*)(void))i;
```
|
This question already has answers here:Closed12 years ago.
Possible Duplicate:What does a type followed by _t (underscore-t) represent?
I have seen many data structures in Linux environment have post-fix of '_t'.
Is there a specific meaning for it?
| It's an abbreviation for "type".
|
Im quite confused that what is difference between these two initializations:
```
int (*p)[10];
```
and
```
int *p[10]
```
I know they both can point to 2D array whose element count in row is 10....
| The first is a pointer to array, the second is an array of pointers.
|
This question already has answers here:Closed12 years ago.
Possible Duplicate:What does a type followed by _t (underscore-t) represent?
I have seen many data structures in Linux environment have post-fix of '_t'.
Is there a specific meaning for it?
| It's an abbreviation for "type".
|
Im quite confused that what is difference between these two initializations:
```
int (*p)[10];
```
and
```
int *p[10]
```
I know they both can point to 2D array whose element count in row is 10....
| The first is a pointer to array, the second is an array of pointers.
|
Can anyone tell me how to verify the Password-based P12 file using openssl? Logic or sample code will be much helpful.
| You can find a code sample that :- opens a pkcs#12 file with password- extracts the private key and certificates
in the openssl source code at :
```
./demos/pkcs12/pkread.c
```
|
Hi I am working with a matrix of 448*448 elements of real(signed) data and wanted to display it as grayscale image in C as i did in MATLAB usingimagesc. Can anyone tell me which is the fastest and easiest library or code to display the grayscale image from the matrix in C?
Thanks.
| Also look atopenCVlibs. These libs are quite good. It has both c and C++ interface.
|
Can anyone tell me how to verify the Password-based P12 file using openssl? Logic or sample code will be much helpful.
| You can find a code sample that :- opens a pkcs#12 file with password- extracts the private key and certificates
in the openssl source code at :
```
./demos/pkcs12/pkread.c
```
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.