question
stringlengths 24
425
| answer
stringlengths 5
405
|
---|---|
```
#include <stdio.h>
#include <time.h>
int main (void)
{
double diff = 0.0;
time_t start;
time_t stop;
time(&start);
print("Enter millisecond to stop");
```
so what is code should add to stop timer after given interval of timer
| ```
int seconds;
scanf ("%d",&seconds);
stop = 0;
while (stop < start + seconds)
time(&stop);
```
|
I would like to change the value of the third letter in apple to "a".
Using the indirection this way gives me a compiler error saying:
invalid type argument of unary ‘*’ (have ‘int’)
```
#include<stdio.h>
int main(){
char c[6]="apple";
*c[2]="a";
return 0;
}
```
| You should use the following:
```
c[2]='a';
```
In C and C++"x"is a type ofconst char [2]. To specify a character you need to use'x'that is a type ofconst char.
|
I have char[] as such
```
char string[] = "Hello world !!!";
```
when I'm trying to reallocate it's memory I'm getting error
```
realloc(string, 50); // error here
```
| You can onlyreallocthings youmalloc/calloc/realloc'ed. Achararray is not any of those things, so it is normal for you to get an error in this case.
|
```
#include <stdio.h>
#include <time.h>
int main (void)
{
double diff = 0.0;
time_t start;
time_t stop;
time(&start);
print("Enter millisecond to stop");
```
so what is code should add to stop timer after given interval of timer
| ```
int seconds;
scanf ("%d",&seconds);
stop = 0;
while (stop < start + seconds)
time(&stop);
```
|
my question is about
```
gets()
```
and
```
puts()
```
are they a perfect solution for string input and output?
| getsis marked as obsolescent in C99 and has been removed in C11 because of security issues with this function. Don't use it, usefgetsinstead. As an historical note,getswas exploited (in fingerd) by the first massive internet worm: the inet worm back in 1988.
putsfunction is OK if it fits your needs.
|
I'm trying my C code to build with autotools on mingw+msys.
Could you tell me how to link library likews2_32.libwhen I useautotools.
I think I have to editconfigure.acorMakefile.am.
| Like this, in the Makefile.am:
```
AM_LDFLAGS = -lws2_32
bin_PROGRAMS = myApp
myApp_SOURCES = myApp.c
...
```
|
I have .c files and .f files which are interdependent.
That means, the function used in .c files are defined in .f files.
Now, I want to call for some functions in .c file from my R. How can I do this using R CMD SHLIB?
| Oh, I figured out this can be easily done by
```
R CMD SHLIB code1.f code2.c -o myLib
```
Then in R, I can call the myLib via
```
dyn.load("myLib")
```
|
I am just back from an interview and this question is bugging me. I was asked to write an equivalent expression forx % 8and I couldn't get it. I know it's something to do with 8 being in powers of 2 but I just can't figure it out. This seems like a great programmer community so I'm hoping anyone here can answer this?
| x&7is the answer. (I'm not some hot shot I just googled it)
|
I am just back from an interview and this question is bugging me. I was asked to write an equivalent expression forx % 8and I couldn't get it. I know it's something to do with 8 being in powers of 2 but I just can't figure it out. This seems like a great programmer community so I'm hoping anyone here can answer this?
| x&7is the answer. (I'm not some hot shot I just googled it)
|
```
main()
{
int a = 10, b = 5, c = 5;
int d;
d = a == (b + c);
printf("%d", d);
}
```
OUTPUT: 1
Can anyone please explain how this value is assigned to d??
| ==has a higher precedence than=, so
```
d = a == (b + c);
```
is equivalent to:
```
d = (a == (b + c));
```
it tests ifais equal tob + c,1if true, and0if false.
|
I am trying to gcc my library with another static library and I get this error while runtime
```
undefined symbol: security_getenforce
```
I am thinking this is related to selinux, not sure though... how do I resolve this?
Thanks,
Vik.
| Figured it out, use -lselinux as the flag to resolve the issue and load the necessary libraries.
|
```
int a[10];
int *p = a; //way 1
int *p1 = &a[0]; //way 2
```
Could you tell me the differences between two ways above?
| There is no difference. Both assign the address of the first element to the pointerpandp1respectively.
In the first case,ais automatically converted to the address of the first element. In the second case it uses the address of the first element explicitly.
|
Trying to open a file using open(). Returns the correct file descriptor when we call it like so:
```
fd = open("a.txt", O_RDONLY);
```
But when we use a token generated from strtok(), it returns -1:
```
token = strtok(NULL, " ");
fd = open(token, O_RDONLY);
```
| Correctly guessed in comments:tokenis not actually the same string as"a.txt", but contains extra whitespace at the end, which makes it hard to see when printed as a string.
|
I'm trying
```
typedef struct
{
int x = 5;
char str[20];
} nodeStr;
```
It works in C++, but doesn't in C. For it to work in C I need to cut the definition ofx(i.e.,= 5) from the code. Is there in conceptual difference in C and C++ explaining this? Thanks!
| In-class initialization is a new C++11 feature - if you use a (not much) older C++ compiler, it won't compile. So yes, it's a difference between C and C++.
|
This question already has answers here:With arrays, why is it the case that a[5] == 5[a]?(20 answers)Closed9 years ago.
What makes this construction?
```
int a[10];
int x;
x = 2[a];
```
I do not understand what makes 2 [a]. It is another senility of C language?
| It is
2[a] = *(2 + a) = *(a + 2) = a[2]
Note:+operator holds commutative property
|
I am using a serial port in my c program. If there is nothing connected to this serial port, what can I expect from a call of read( )in my program? Would the program hang or return an error?
Thank you!
| From theman pageit would probably returnEBADF.
Have you tried it? If not, it might be better to tell us what you want to achieve (block until something is connected, throw an error, etc.) so users can better guide you.
|
I have 2 enums.
```
typedef enum {
BLUE = 1,
RED = 2
} FavoriteColor;
typedef enum {
ORANGE = 1,
YELLOW = 2,
RED = 3
} Color;
```
In my code how can I refer to a specific RED from FavoriteColor enum, but not Color enum?
| You can't. And the compiler should warn you about that.
enumconstants live in the global namespace. The second definition is a redefinition that should produce an error.
|
I am using a serial port in my c program. If there is nothing connected to this serial port, what can I expect from a call of read( )in my program? Would the program hang or return an error?
Thank you!
| From theman pageit would probably returnEBADF.
Have you tried it? If not, it might be better to tell us what you want to achieve (block until something is connected, throw an error, etc.) so users can better guide you.
|
I have 2 enums.
```
typedef enum {
BLUE = 1,
RED = 2
} FavoriteColor;
typedef enum {
ORANGE = 1,
YELLOW = 2,
RED = 3
} Color;
```
In my code how can I refer to a specific RED from FavoriteColor enum, but not Color enum?
| You can't. And the compiler should warn you about that.
enumconstants live in the global namespace. The second definition is a redefinition that should produce an error.
|
I am using a serial port in my c program. If there is nothing connected to this serial port, what can I expect from a call of read( )in my program? Would the program hang or return an error?
Thank you!
| From theman pageit would probably returnEBADF.
Have you tried it? If not, it might be better to tell us what you want to achieve (block until something is connected, throw an error, etc.) so users can better guide you.
|
I have 2 enums.
```
typedef enum {
BLUE = 1,
RED = 2
} FavoriteColor;
typedef enum {
ORANGE = 1,
YELLOW = 2,
RED = 3
} Color;
```
In my code how can I refer to a specific RED from FavoriteColor enum, but not Color enum?
| You can't. And the compiler should warn you about that.
enumconstants live in the global namespace. The second definition is a redefinition that should produce an error.
|
I have an array that is already sorted in partitions of 4:
```
2, 23, 45, 55, 1, 4, 23, 74545, 75, 234, 323, 9090, 2, 43, 6342, 323452
```
What would be the most efficient way to sort this array? Note: the array size is always even and the program knows that every 4 elements are sorted.
| I think you can usemerge sortfor problems like this.
|
I have an array that is already sorted in partitions of 4:
```
2, 23, 45, 55, 1, 4, 23, 74545, 75, 234, 323, 9090, 2, 43, 6342, 323452
```
What would be the most efficient way to sort this array? Note: the array size is always even and the program knows that every 4 elements are sorted.
| I think you can usemerge sortfor problems like this.
|
If I have two file pointers and do the following:
```
FILE *f1,*f2;
f1= fopen("inputfile","r+");
f2=f1;
fclose(f2);
```
Is the equal operation valid, if it is, will the last line close f1 as well?
| It is enough, both will be closed and both will point to a closed file.
Assigningf2=f1doesn't do anything magical (increasing a reference count or duplicating descriptors).
|
I'm trying to rename a file through a system() command and I get (The filename, directory name, or volume label syntax is incorrect)
This is the line from my code:
system("ren" "C:\Users\Mac\Desktop\new folder\03 Elfsong - Shar.mp3 test.mp3");
What is the syntax problem here?
| renis a cmd.exe built-in command, it's not a standalone executable, so you'd have to do
```
system("CMD", "/c ren originalname newname");
```
|
I want to compare datetime in C. I googled but I didn't get any proper solution. I am having datetime in string format i.e date1 = "2014-02-13 12:22:21" and date2 = "2014-02-10 12:22:21".
Now, I want comparison b/w date1 and date2.
Please suggest me proper solution.
| Just usestrcmp. It works because with this particular date/time format, the lexicographical order is the same as the chronological order.
|
If I have an instruction:
```
imull $eax, $ecx
```
so that it is multiplying what is stored in the two registers, where is the answer stored?
| Different assemblers work differently. For the GNU Assembler the result will go in$ecx. This is the opposite convention from most windows assemblers.
|
How can I compile it on a 32-bit system so it can run as backward compatible under a 64-bit system? I know it can be done because Adobe, Dropbox and other companies have such binaries. How should I link them, dynamically, statically? Static only some libraries and other dynamic?
I'm talking about a simple code like:
```
int main() {
printf("Hello world!\n");
}
```
Thank you!
| Normally. Then install the 32-bit libraries on the 64-bit system.
|
How can I compile it on a 32-bit system so it can run as backward compatible under a 64-bit system? I know it can be done because Adobe, Dropbox and other companies have such binaries. How should I link them, dynamically, statically? Static only some libraries and other dynamic?
I'm talking about a simple code like:
```
int main() {
printf("Hello world!\n");
}
```
Thank you!
| Normally. Then install the 32-bit libraries on the 64-bit system.
|
I am writing a C program, that uses *NIX System calls. Now, when the user calls for deleting a particular file, I want to remove all the symbolic links created to the file, also to be removed. How can this be achieved?
| You can't, unless you search the whole directory tree, or you have some other means of knowing where these symbolic links are. A file doesn't "know" which symlinks point to it. You have to locate each symlink on your own andunlink()it.
|
I am writing a C program, that uses *NIX System calls. Now, when the user calls for deleting a particular file, I want to remove all the symbolic links created to the file, also to be removed. How can this be achieved?
| You can't, unless you search the whole directory tree, or you have some other means of knowing where these symbolic links are. A file doesn't "know" which symlinks point to it. You have to locate each symlink on your own andunlink()it.
|
Can I put#define MY_VAR 1in a file and#define MY_VAR 2in a different file without any problem?
In other words, is#definea local or a global definition?
| The answer depends on what kind of file you are talking about:
If it is a header file, then your#define-d constant is visible in all files including the headerIf it is a .c/.m/.mm./.cpp file, then#defined constant is limited in scope to the file where it is defined.
|
Can I put#define MY_VAR 1in a file and#define MY_VAR 2in a different file without any problem?
In other words, is#definea local or a global definition?
| The answer depends on what kind of file you are talking about:
If it is a header file, then your#define-d constant is visible in all files including the headerIf it is a .c/.m/.mm./.cpp file, then#defined constant is limited in scope to the file where it is defined.
|
when i'm tryin' to use malloc with string pointers to scan, it's givin' a segmentation fault
```
main(){
char *a;
a = (char)malloc(50);
printf("enter a string\t");
scanf("%s", a);
printf("%s\n", a);
}
```
| ```
a = (char)malloc(50);
```
Here, you meant to cast its type tochar *instead ofchar.
Note that it's better not to cast the return type ofmalloc. SeeDo I cast the result of malloc?
|
For example having string:
```
Hello World!
```
How to make strcopy function working from position 6 and copy onlyWorld!to another buffer ?
| ```
char source[] = "Hello World!";
char destination[7]; // 7 = strlen("World!") + 1
strcpy(destination, source + 6);
```
|
Is there a way to grow an array in C, but only if the memory can be grown in place (That is, fail to grow if the pointer needs to be changed)?
| In standard C there is no function capable of doing that.
|
```
int main()
{
struct books
{
char name;
float price;
}b1;
printf("%u %u",&b1.name,&b1.price);
}
```
When I run the above code, I get the following output:-
```
2686728 2686732
```
As thesizeof(char)is 1, so why there is a difference of 4 in the above two addresses?
| Padding. The compiler inserts 3 bytes of padding between thenameandpricefields so accessingpricedoesn't run into alignment troubles.
|
```
int main()
{
struct books
{
char name;
float price;
}b1;
printf("%u %u",&b1.name,&b1.price);
}
```
When I run the above code, I get the following output:-
```
2686728 2686732
```
As thesizeof(char)is 1, so why there is a difference of 4 in the above two addresses?
| Padding. The compiler inserts 3 bytes of padding between thenameandpricefields so accessingpricedoesn't run into alignment troubles.
|
This question already has answers here:Detect 32-bit or 64-bit of Windows(14 answers)Closed9 years ago.
I was looking for a way to determine the above. I could not really find it easily and google somehow couldn't help me much with it too.
Thanks.
| You need theGetNativeSystemInfo()API Call. The information you are looking for will be returned in theSYSTEM_INFOstructure in thewProcessorArchitecturemember.
|
This question already has answers here:Detect 32-bit or 64-bit of Windows(14 answers)Closed9 years ago.
I was looking for a way to determine the above. I could not really find it easily and google somehow couldn't help me much with it too.
Thanks.
| You need theGetNativeSystemInfo()API Call. The information you are looking for will be returned in theSYSTEM_INFOstructure in thewProcessorArchitecturemember.
|
I have an unsigned char and i want to write0x06on the four most significant, and i want to write0x04on its 4 least significant bits.
So the Char representation should be like0110 0010
Can some can guide me how i can do this in C?
| ```
c = (0x06 << 4) | 0x04;
```
Because:
```
0x04 = 0000 0100
0x06 = 0000 0110
0x06<<4 = 0110 0000
or op: = 0110 0100
```
|
If type of the value cannot be analyzed or found out by looking into the bits(As written in books I have referred), how does the machine know how the value should be manipulated?
| C and C++ arestatically typed, meaning that types are a compile-time concept. The compiler generates code to manipulate the bits in a manner appropriate to the type; the machine executes that code, and doesn't need to know anything about the type.
|
I'm trying to reverse some pointers that were read from a binary encoded file.
When I try to reverse the pointer 0xfffe0024540 stored in big endian format, I get
0xffffffffe0024540
The pointer is stored in the file in the format:
0000 ff0f 02e0 4045
| The behaviour of right-shifting a negative signed integer is implementation dependent,
as far as I remember. You should replacelongbyunsigned longoruint64_t.
|
New to both python, and fairly beginner in C. Why will the subject code return an error in python?
Does the assignment not have a return value?
| This is simply not valid in Python. You can't use an assignment as an expression.
|
I went through the documentation, but still didn't get what does optlen do ingetsockopt(int s, int level, int optname, void *optval,
socklen_t *optlen), can anyone explain?
| You set it to the size of the data item you're receiving the option value into. On return the size may have been adjusted.
The documentation does say that.
|
Givennandmunsigned integral types, will the expression
```
(n & m) <= m
```
always be true ?
| Yes, it is true.
It should be readily apparent that a necessary condition fory > xis that at least one bit position is set to1inybut0inx. As&cannot set a bit to1if the corresponding operand bits were not already1, the result cannot be larger than the operands.
|
New to both python, and fairly beginner in C. Why will the subject code return an error in python?
Does the assignment not have a return value?
| This is simply not valid in Python. You can't use an assignment as an expression.
|
I went through the documentation, but still didn't get what does optlen do ingetsockopt(int s, int level, int optname, void *optval,
socklen_t *optlen), can anyone explain?
| You set it to the size of the data item you're receiving the option value into. On return the size may have been adjusted.
The documentation does say that.
|
Givennandmunsigned integral types, will the expression
```
(n & m) <= m
```
always be true ?
| Yes, it is true.
It should be readily apparent that a necessary condition fory > xis that at least one bit position is set to1inybut0inx. As&cannot set a bit to1if the corresponding operand bits were not already1, the result cannot be larger than the operands.
|
Suppose I have
```
char *t = "XX";
```
I am wondering what is the type of &t. Is it char or array?
| The type of&tfor any expression is a pointer to the type oft. In this case the type oftischar*hence the the type of&tischar**
|
If I have
```
a = 3;
b = 5;
```
How can I make it so that
double result = 3e5, but only using variables?
I know aeb won't work, obviously.
| Try:
```
double result = a * pow(10.0,(double)b);
```
Or, with GNU extensions:
```
double result = a * exp10((double)b);
```
In either case, #include math.h and link with the math library (eg.-lm). This is likely much more efficient than piecing together a string and converting to double.
|
How to find which data is currently union variable is holding out of the many fields present in the union without keeping extra variable to track it.
| Unfortunately, you can't do this. All of the variables are holding some or all of the same data in memory, whether that data is meaningful or not.
|
How to find which data is currently union variable is holding out of the many fields present in the union without keeping extra variable to track it.
| Unfortunately, you can't do this. All of the variables are holding some or all of the same data in memory, whether that data is meaningful or not.
|
What is a good way to create a double from a coefficient and a power of 10? Or in other words, what is a good way to create a double from the significand and the exponent of a written scientific notation value at runtime?
| Not sure about numerical quality, but the obvious way would be:
```
double make_double(double coefficient, int power)
{
return coefficient * pow(10.0, power);
}
```
|
This question already has answers here:C pointer to array/array of pointers disambiguation(12 answers)Closed9 years ago.
```
int (*ptr)[10];
```
I know whatint *ptr[10];its a 10 member array where each element is a pointer to an integer.
But what does the above piece code create ?
| ```
int *ptr[10]
```
is an array of 10intpointers,
int (*ptr)[10]
is a pointer to an array of 10ints
|
This question already has answers here:C pointer to array/array of pointers disambiguation(12 answers)Closed9 years ago.
```
int (*ptr)[10];
```
I know whatint *ptr[10];its a 10 member array where each element is a pointer to an integer.
But what does the above piece code create ?
| ```
int *ptr[10]
```
is an array of 10intpointers,
int (*ptr)[10]
is a pointer to an array of 10ints
|
gcov primarily is a code coverage tool. However, is there any way we can find LOC (excluding comments...etc) with gcov?
It must be easy for gcov to get that information, but I didn't find any documentation on that.
Also, let me know if you know any other tool which can calculate lines of code in such manner.
| You can also look atSLOCCount, which is available in packages on most Linux distributions.
|
I'm trying to create a folder inside /var/mobile/Library/MyAppName. I read on internet that I must use the command:
```
mkdir(“/var/mobile/Library/YOURAPPNAME”, 0755);
```
but xcode cannot recognize that command... how can I solve?
| Formkdir(), add
```
#include <sys/stat.h>
```
You can get this information from "man 2 mkdir" on the command line,
or fromhttp://pubs.opengroup.org/onlinepubs/009695399/functions/mkdir.html.
|
I'm trying to create a folder inside /var/mobile/Library/MyAppName. I read on internet that I must use the command:
```
mkdir(“/var/mobile/Library/YOURAPPNAME”, 0755);
```
but xcode cannot recognize that command... how can I solve?
| Formkdir(), add
```
#include <sys/stat.h>
```
You can get this information from "man 2 mkdir" on the command line,
or fromhttp://pubs.opengroup.org/onlinepubs/009695399/functions/mkdir.html.
|
I have a statically linked executable compiled from a C program.objdump -x a.outindicates the presence of the.eh_framesection, even afterstrip -s.Why is this section useful in a C(non-C++) program?What are the risksof stripping it (withstrip -R .eh_frame)?
| From remyabel's comment and OP's confirmation, the answer to the OP question is available via another SO question as linked by:
Why GCC compiled C program needs .eh_frame section?
|
This question already has answers here:MIN and MAX in C(16 answers)Closed9 years ago.
Is there any library function incfor finding out the largest number between two numbers?
| You can do
```
#define new_max(x,y) (((x) >= (y)) ? (x) : (y))
#define new_min(x,y) (((x) <= (y)) ? (x) : (y))
```
valter
|
If I try objdump -t /usr/bin/sort command it says no symbols. But it seems to work on my programs. What is the reason for this?
| The symbols of /usr/bin/sort has been removed, e.g. with thestripprogram - for most executables the symbol table is not needed (or only needed for debugging).Hereis a bit more info.
|
I have the following data
```
uint16_t a[1] = { 0x2321 };
```
I want to convert to uint8_t as:
```
uint8_t b[1] = { 0x21 };
```
How can I do it in a C program?
| Cast the lower byte:
```
uint16_t a[1] = {0x2321};
uint8_t b[1] = {(uint8_t)(a[0] & 0xFF)};
```
|
I have the following data
```
uint16_t a[1] = { 0x2321 };
```
I want to convert to uint8_t as:
```
uint8_t b[1] = { 0x21 };
```
How can I do it in a C program?
| Cast the lower byte:
```
uint16_t a[1] = {0x2321};
uint8_t b[1] = {(uint8_t)(a[0] & 0xFF)};
```
|
I am using C/C++ Eclipse. Is there an option in the IDE or an external tool to figure out the chain as to how a header file is eventually being included?
| You could just put an#errorin the header file, the compiler should give you a trace like:
```
In file included from someheader.h:1:0,
from myheader.h:1,
from mysourcefile.c:1:
header_im_tracing.h:1:2: error: #error foobar
```
|
Can we write or call "C code" in XAML for Windows Phone 8,
i'm having C library and i have to use it in WP8 application. any idea..
| Yes you can - but you have to link it against a C++ project. What you need is a WinRT component that links against that library and acts as a wrapper. That component can then be used in C#.
Check outMSDN docs.
|
I know that we can create a macros in c- language by using preprocessor(#define), but can we create macros with out using preprocessors i;e without #define. if there is any please help me..
Thank you
| In the standard C language, macros are created with#define. There is no other way.
|
I don't know why this code works. it supposed to print out every student which follows chem. but why does a number for instance 21&4(student 123001) evaluate to true while a number like 49&4(123008) doesn't?
| I think it is due to bit operation AND.
In binary
```
49 is 110001
4 is 000100
& = 000000
```
So it evaluates tofalse
wheras
```
21 is 10101
4 is 00100
& = 00100
```
So you get a non-zero result which is true.
|
I am trying to setup MinGW with NetBeans IDE.
I've downloaded mingw-get-setup.exe but i do not understand which packages should i choose for c and c++ compiler.
please help
| For basic C/C++ installation you can choose following options from Installation Manager as highlighted :
Msys-Base is not necessary
|
```
#include<stdio.h>
void main()
{
float a=10.5;
printf("%d%d",sizeof(a),sizeof(10.5));
}
```
OUTPUT:
4 8
I want to know why it happens?
| In C a floating point literal is actually a double unless you suffix it with an f (i.e.10.5f).
|
Say there is a very large number, 100 digits which is stored in an array. Now i want to divide this number by another number(say 2) , Can anyone suggest how to do it?
| Try to do it exactly as you would do that on paper. For small divisors (as 2) this is an O(d) algorithm (where d is the number of digits) and it is impossible to find anything asymptotically better since you need to check each digit at least once.
|
Is there anyway in C to get an image, stream by stream and how can I understand how many stream there are in an Image?
the Image is in JPEEG type.
and for saving this stream in another file I'll have any problem?
| You can have a look to the free OpenCV library :http://opencv.org/
Here there is a tutorial with some examples :http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/
It's largely used for this kind of treatments.
|
I have a C program running on a Unix box.
I would like to print a timestamp to an output file - at the moment I use the commanddateto print the datetime on the terminal.
```
fprintf(outputfile, "%s ", date);
```
How do I go about doing this?
| Use POSIXstrftime(3) - format date and timefor a C solution. It use the same format strings asdate(1)
I also recommend you read thestandard library intro(3).
|
I have mp4 video which has around 50000 frames of size 1920x720. I have to remove a specific area in the video (all frames). Can you suggest a method in MATLAB?
| Specify a ROI(Region of Interest) for each individual frame of the video, where the ROI is the specific area that you wanted to remove. Quite simple. Hope my advice helped. If u are still not sure, comment on this answer, I will add in more hints.
|
I have mp4 video which has around 50000 frames of size 1920x720. I have to remove a specific area in the video (all frames). Can you suggest a method in MATLAB?
| Specify a ROI(Region of Interest) for each individual frame of the video, where the ROI is the specific area that you wanted to remove. Quite simple. Hope my advice helped. If u are still not sure, comment on this answer, I will add in more hints.
|
I have mp4 video which has around 50000 frames of size 1920x720. I have to remove a specific area in the video (all frames). Can you suggest a method in MATLAB?
| Specify a ROI(Region of Interest) for each individual frame of the video, where the ROI is the specific area that you wanted to remove. Quite simple. Hope my advice helped. If u are still not sure, comment on this answer, I will add in more hints.
|
Doxygen seems to expect C++ and lists my structs as "classes" in the HTML output.
How can I get Doxygen to process my source as C not C++?
| Try
```
OPTIMIZE_OUTPUT_FOR_C=YES
```
in yourDoxyfile, see if that's more to liking.
|
How to
```
if (x == 1) printf("2\n");
else if (x == 2) printf("1\n");
else printf("0\n");
```
using bitwise operators?
My attempt is:
```
for (x = 0; x < 8; x++) {
printf("%d\n", 0x03 & (0x03 ^ x));
}
```
Output:
```
3
2
1
0
3
2
1
0
```
Desired output:
```
0
2
1
0
0
0
0
0
```
| This is insane, but I finally figured it out:
```
printf("%d\n", (3 & ~(x & 3)) & (0xfc >> (x << 1)));
```
|
So, that's the question: can I increment theivariable insideforloop?:
```
for(int i = 0; i < 1000; i++)
{
i++; // is this legal? if not what is the alternative?
}
```
| Absolutely legal but not very intuitive.
Consider using a while loop instead if you need to manipulate your looping in this way (it's just a code clarity thing, not a legal thing).
|
I understand a condition is supposed to be for example y==3, but y-3 is totally confusing to me. I can't understand this code. If y-3 is true it prints 1. How can y-3 be true or false?
| The expressiony - 3results in a value which can be tested for truthness. In C 0 is false and any non-zero value is true. Sayingif (y - 3)is essentially sayingif (y - 3 != 0)or even more succinctlyif (y != 3)
|
I'm writing this code to use sizeof() function with a char array of 7 elements, I thought that the output should be 8 because of the 7 elements PLUS the terminator of the array but surprised that the output was 5?? HOW COME?
```
#include<stdio.h>
int main(void)
{
char str[]="S\065AB";
printf("\n%d",sizeof(str));
return 0;
}
```
| \065is a single character, represented as an octal escape sequence.
|
i cannot figure out why NULL is not printed
```
#include "stdio.h"
#include "stddef.h"
typedef struct{
int info;
struct DEMO1* next;
} DEMO1;
int main()
{
int temp;
DEMO1 *head ;
if(head==NULL)
printf("NULL");
}
```
| Memory is not initialized upon allocation. You cannot expect it to have a particular value until you set it.
|
I want to know how to make Cmake give me a target that will allow me to save the .i files from myCprogram with the macro expansion, etc completed.
Will I need to make a custom target to do this?
| If your are using the Makefile generator, then there are already targets for .i files. Typemake help, and you will see all the targets, including those suffixed by.i,.s, and.o.
|
I want to know how to make Cmake give me a target that will allow me to save the .i files from myCprogram with the macro expansion, etc completed.
Will I need to make a custom target to do this?
| If your are using the Makefile generator, then there are already targets for .i files. Typemake help, and you will see all the targets, including those suffixed by.i,.s, and.o.
|
I am trying to access a column from an excel document from a C code in Linux. Is there a simple way to do this? There are more than 47000 rows and I want to store the data of particular column into an array of data structure.
| Use xlsLib library for parsing excel file. You can find more informationhereandHere
|
Is it possible, under some circumstance, in ANSI-C, to start arrays in index 1 instead of 0? (some compiler options which stays under the definition of ANSI-C, not MACROS or such)
e.g
```
int arr[2];
arr[2] = 5;
arr[1] = 4;
```
will be valid code which will behave properly.
| No.
There is no such thing in ANSI C.
|
How can I castvoid*toint ( * () ) (int,...)?
Thevoid*is coming from adlsym. This code isn't compiling:
```
typedef int ( *PSYS () ) (int,...);
PSYS getf = (PSYS) dlsym(lib, "function" );
```
| PSYS is the type of a function, not a pointer to a function. You want
```
typedef int ( *PSYS () ) (int,...);
PSYS* getf = (PSYS*) dlsym(lib, "function" );
```
|
I would like to know what does this expression test:
```
if ((a=b)!=0)
```
Is it equivalent to(if (a!=0))?
| When used as an operator,=both assigns the value from the right side to the variable on the left side and returns the new value of that variable (for example, ifais an integer value,(a=3.4)returns 3). So this is equivalent to:
```
a=b;
if(a!=0)
```
|
I'm not sure what I am doing wrong here, I am following a tutorial online(thenewboston) and I am getting an error that says "w used as the name of the previous parameter rather than as part of the selector."
```
-(void)setWH: (int) w:(int) height;
```
| You're missing part of the selector name:
```
- (void)setWidth:(int)width height:(int)height;
// ^--- You're missing this.
```
|
I'm programming in C. I'd like to search a string inside of a string.
Are there any built-in function that does that in string.h ? Or do you know how to create one ?
| Are there any built-in function that does that in string.h ?
Yes. Take a look atstrstr(), which is part of the standard library and declared in string.h.
|
I have set the "Architectures" setting in Xcode to armv7, armv7s.
What happens when I run my app on an arm64 device like the iPhone5s.
Will the size oflongbe 64bit or 32bit ?
| Thecompilercreates 32-bit or 64-bit code, depending on the selected architecture.
Therefore, if the app is compiled for a 32-bit architecture (like armv7, armv7s),
the size oflongis 32-bit, regardless of the actual device that the code is
running on.
|
I'm programming in C. I'd like to search a string inside of a string.
Are there any built-in function that does that in string.h ? Or do you know how to create one ?
| Are there any built-in function that does that in string.h ?
Yes. Take a look atstrstr(), which is part of the standard library and declared in string.h.
|
I have set the "Architectures" setting in Xcode to armv7, armv7s.
What happens when I run my app on an arm64 device like the iPhone5s.
Will the size oflongbe 64bit or 32bit ?
| Thecompilercreates 32-bit or 64-bit code, depending on the selected architecture.
Therefore, if the app is compiled for a 32-bit architecture (like armv7, armv7s),
the size oflongis 32-bit, regardless of the actual device that the code is
running on.
|
This question already has an answer here:Determining if file has been copied or not in C [closed](1 answer)Closed9 years ago.
In Windows, if you go to a file's properties it shows the last access time right under the time last modified. This changes when I copy it.
How do I view this in C?
| You can use theGetFileTime()function to get it. ThisMSDN articlehas more details about file times.
|
I know how to count nodes on a level of a tree recursively (used tips from this answerhttps://stackoverflow.com/a/12879973/2663649), but I can't form an iterative algorithm, and not sure if I should use stack or pointer array to save previous nodes (to return to root).
| You can turn your recursive algorithm into an iterative one.Just use a stack structure where you do the recursion.
|
I have a text file in which of its line, there is two numbers. each of them are nodes of a graph. the size of the file is 1.5 gb and had has 92522018 lines. the wanted thing is the node with maximum number of edges.
i need the the array for solving this problem.
is there any way to allocate this size of array or even bigger?
| For C,
Usemalloc
For C++,
UseVectors
|
I wrote a simple code with dev but it does not return any thing.but with code block answer shows.what is the problem?
```
#include <stdio.h>
int main() {
int x,y,z;
scanf("%d%d",&x,&y);
while(z!=0){
z=x%y;
printf("%d",z);
}
return 0;
}
```
| Two problems I can see:
```
1. Value to z is un-assigned. So garbage.
2. Value of z will not change, so it's infinite loop.
```
|
The following prints the percentage of memory used.
```
printf (TEXT("There is %*ld percent of memory in use.\n"),
WIDTH, statex.dwMemoryLoad);
```
WIDTH is defined to be equal to 7.
What does TEXT mean, and where is this sort of syntax defined in printf?
| As others already said,TEXTis probably a macro.
To see what they become, simply look at the preprocessor output. If are using gcc:
```
gcc -E file.c
```
|
I have a text file in which of its line, there is two numbers. each of them are nodes of a graph. the size of the file is 1.5 gb and had has 92522018 lines. the wanted thing is the node with maximum number of edges.
i need the the array for solving this problem.
is there any way to allocate this size of array or even bigger?
| For C,
Usemalloc
For C++,
UseVectors
|
I wrote a simple code with dev but it does not return any thing.but with code block answer shows.what is the problem?
```
#include <stdio.h>
int main() {
int x,y,z;
scanf("%d%d",&x,&y);
while(z!=0){
z=x%y;
printf("%d",z);
}
return 0;
}
```
| Two problems I can see:
```
1. Value to z is un-assigned. So garbage.
2. Value of z will not change, so it's infinite loop.
```
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.