question stringlengths 25 894 | answer stringlengths 4 863 |
|---|---|
I am practicing algorithms problems online, and encountered an input problem:
I know how to read
```
1 2 3 -4 5
```
using
```
int *p = (int*)malloc(sizeof(int) * size);
while(scanf("%d", p++) != EOF) {
//
}
```
But the problem's input is defined as
```
[1, 2, 3, -4, 5]
```
how to read this format input into... |
I believe this can get you started,
```
int main () {
int size = 5;
int *p = (int*)malloc(sizeof(int) * size);
char buf[200] = {0};
fgets(buf, 200, stdin);
char *token = strtok(buf, "[, ");
while(token) {
*p = atoi(token);
printf("next is %d,\n", *p);
token = strtok(... |
I have aconst char*which represents a path I want to split it into an array of strings at character/so I can do the search step by step.
I tried doing
char* str2 = strtok(str1,"/")
but my compiler returns a
warning: initialization discards ‘const’ qualifier from pointer target type
How can I do the split without ... |
strtok(3)andstrtok_r(3)mutate the string in place, which prevents you from passing a const string. You will want to pass a copy anyway, as you don't want your initial string to be mutated and become unusable.
Here's how you can do it withstrdup(3):
```
char* strtmp = strdup(str1);
char* str2 = strtok(strtmp,"/");
//... |
I am wondering, what does below mean
in .h, it has
```
typedef void *(*some_name)(unsigned int);
```
And then in .c
```
some_name rt;
some_name State= 0;
unsigned int t = 1;
rt = (some_name) State(t);
```
|
It creates an aliassome_namefor a pointer to a function with a return typevoid*and a single unsigned int parameter. An example:
```
typedef void *(*my_alloc_type)(unsigned int);
void *my_alloc(unsigned int size)
{
return malloc(size);
}
int main(int argc, char *argv[])
{
my_alloc_type allocator = my_alloc;
... |
I have QQuickWindow * _mainWindow and in OS Windows I just write
::ShowWindow(reinterpret_cast<HWND>(_mainWindow->winId()), SW_MINIMIZE);
and it's works! But I do not know how it make in OS linux, I googled about x11 library, but don't understand how use it. Please help.
I try minimize application window because in... |
```
#include <X11/Xlib.h>
#include <QX11Info> // from qt q11extras
// function for minimze your app
XIconifyWindow(QX11Info::display(), _mainWindow->winId(), QX11Info::appScreen());
```
|
I try to get strings from userspace within the kernel module. Till I set my char size manually it seems working properly. However, I need to make it dynamic so if I uselenparameter it shows weird symbols on the end of char.
```
static ssize_t msecurity_write(struct file *filep, const char *buffer, size_t len, loff_t ... |
C strings are terminated by anullcharacter. This character is not included in any string length calculation but must be included.
Thus a string of length 12 will need 13 bytes with the last byte equal to 0.
|
Suppose I have a structure named 'Item'. I have to make a member of Item double pointer inside another structre.
```
struct Item{
char *name;
int price;
double weight;
};
struct Inventory{
struct Item double* item;
int NUMITEMS;
};
```
|
Unfortunately, the termdouble pointeris ambiguous. It can mean two different things:
Pointer to doubledouble *ptr;Pointer to pointerT **ptr;whereTis any type. It could bedouble:)
Which of these is depending on context.
So in your case, do this:
```
struct Inventory{
struct Item **item;
int NUMITEMS;
};
```... |
I'm learning socket programming using bookUnix Network Programming. Here are two pieces of code from this book:
As we can see, it callsFD_ISSETafterFD_SETwithout callingselectfunction between them, what's the result? Will it betrueifsockfdis writable?
PS: the source codehttp://www.masterraghu.com/subjects/np/int... |
FD_SETjust sets a bit in a bit mask andFD_ISSETchecks this bit. These calls don't care if this bit represents a file descriptor or not, it is just an integer. If there is nothing in between these calls which manipulates the bit mask (i.e. no call ofselect) then the result ofFD_ISSETreflects exactly what was set withFD... |
Does anyone recognize what the value 1607293133099 might represent as a "timestamp"?
The return data type is defined as:
unsigned long long timestamp;
.. with no reference point or documentation to tell me what the value represents.
The value represents an action completed "now" result; but I am unable to convert ... |
Milliseconds since the start of the Unix epoch (1970): Sunday, December 6, 2020, 22:18:53.099 UTC. Is it a timestamp from about 20 minutes before you asked?
|
What is the time complexity of this little code?
```
int count = 0;
for (int i = n; i > 0; i = i/2) {
for (int j = 0; j < i; j++) {
count++;
}
}
```
I want to know the time complexity of this code. To me I calculated as O(n log n) because outer loop runslogntimes and inner loop runsO(n)times. But i a... |
The exact sum is
```
n + n/2 + n/4 + ... + 1
```
which is
```
n * (1 + 1/2 + 1/4 + ... + 1/n)
```
The sum of the non-negative powers of 1/2 is well known to approach 2 in the limit, so the total sum approaches2*n. As a result, the complexity isO(n);idecreases quickly enough to avoid thelinarithmicgrowth.
|
I am trying write a code for program in C, but i found a problem i am not able to solve. I get a set of input, but the input is not always the same. How do i use scanf to read not always the same amount of data?
Input 1):
```
+ 12345 Lala
```
Input 2):
```
- 12345
```
If i use something like this:
```
scanf("%s ... |
Start by reading the whole line
```
char line[100];
scanf(" %[^\n]", line);
```
or
```
fgets(line, 100, stdin);
```
Then usesscanfto read the values from the line.
```
int itemsRead = sscanf(line, "%s %d %s", a[i], &b[i], c[i]);
```
The return value of sscanf will tell you how many values you successfully read ... |
How should I correctlycheck if given argument is anatural numberin C? I am a very beginner when it comes to C... I already have compared that argument to 1 and 2 by atoi(argv[1]) == 1 ..., but when I pass let's say 1.2137 as an argument, atoi cuts it to 1.
Thanks for any help.
|
You can either uselong strtol(const char* nptr, char** endptr, int base)from the headerstdlib.hto check if your whole string can be converted to a number:
```
char* end;
strtol( argv[1], &end, 10 );
if( *end == '\0' ){
printf( "String is a natural number\n" );
} else {
printf( "String is not a natural number\... |
Here is the code.
```
#include<stdio.h>
int main(int argc,char* argv[])
{
fprintf(stderr,"arg count:%d\n",argc);
return 0;
}
```
When type the following cmd:
```
./a.out x 3 >1.txt //case1
```
I got argc 3. (in this case, a.out x and 3)
But when type the following cmd:
```
./a.out x 3>1.txt //case2
```... |
First of all you have to remember that all redirection is handled by the shell itself, it's not passed on to the program.
The command
```
./a.out x 3 >1.txt
```
have three arguments toa.out: The command itself,xand3.
With
```
./a.out x 3>1.txt
```
then3>1is all part of the redirection handled by the shell. It wi... |
i'm trying to input characters to an array
```
char ArrayChar[3]
("Enter: \n");
for (int i=0; i<3; i++)
scanf("%c", &ArrayChar[i]);
for (int i=0; i<3; i++)
printf("%c", ArrayChar[i]);
```
but i can only enter 2 characters and it can only print 2 characters. At first i thought "the size was 3, i enter 2, th... |
You need to add 1 space on thescanf(see below" %c"), so that it won't read\ncharacter from previous call.
```
scanf(" %c", &ArrayChar[i]);
```
|
I cant really update my C++ compiler right now, and would like to know how I can changestoitoatoiwithout getting a compiling error
```
int getInput(int columns)
{
// declare the variable to hold user input
int userInput;
string userValue;
// prompt for the column number and read the column number
cout... |
Firstly, add#include <cstdlib>to your code to useatoiif you don't have that.
Then, replacestoi(userValue)withatoi(userValue.c_str()).
|
I've been tryring to solve this problem for hours now.
```
void replaceLetters(char *text, char original, char new_char)
{
text = "Randoi";
for(int i = 0; i != '\0'; i++){
if(text[i] == original){
text[i] = new_char;
}
}
```
if I print out text in this function it's correct, but in the other function wher... |
Please see my code.
```
#include <stdio.h>
void replaceLetters(char *text, char original, char new_char)
{
for(int i = 0; text[i] != '\0'; i++)
{
if(text[i] == original)
{
text[i] = new_char;
}
}
}
int main()
{
char text[] = "Randoi";
replaceLetters(text,'n','T');
print... |
Allocating and obtaining a pointer of a struct is quite simple:
```
memScoped {
val str: StructType = alloc<StructType>()
val strPtr: CPointer<StructType> = str.ptr
}
```
But I'm struggling to allocate or get pointer of theInt,UInt,Long,ULongand other primitive data types.
Neither there is any extension t... |
Michael is totally correct, Kotlin primitive types are not supposed to work like that. As explained in thedocumentation, one should use special types representing lvalues in such cases. Something like this should work:
```
memScoped {
val i = alloc<IntVar>()
i.value = 5
val p = i.ptr
}
```
|
I need to do something like this:
```
sizeof(int[width][height][8])
```
but unfortunately in c89 (the standard i have to use) this notation is forbidden, is there any way to do the same thing but using pointer notation?
Here's the error i get
It works fine in c99 but not in c89
|
You can write this instead:
```
(sizeof(int) * (width) * (height) * 8)
```
Make sure you put thesizeof(int)first to forcewidthandheightto be converted tosize_tand avoid a potential integer overflow onwidth * height * 8ifwidthandheighthaveinttype.
|
I have a code (not programmed by me) in which I have some parts where I have something like that:
```
#if CORE_DEBUG
ee_printf("State Bench: %d,%d,%d,%04x\n",seed1,seed2,step,crc);
#endif
```
My question is: what is the correct way to set up this environment variable?
EDIT: I am building the code withthisMakefi... |
It's a compilation flag, like-DCORE_DEBUG.
In some build environments you can enable/disable these as part of your build profile.
|
Allocating and obtaining a pointer of a struct is quite simple:
```
memScoped {
val str: StructType = alloc<StructType>()
val strPtr: CPointer<StructType> = str.ptr
}
```
But I'm struggling to allocate or get pointer of theInt,UInt,Long,ULongand other primitive data types.
Neither there is any extension t... |
Michael is totally correct, Kotlin primitive types are not supposed to work like that. As explained in thedocumentation, one should use special types representing lvalues in such cases. Something like this should work:
```
memScoped {
val i = alloc<IntVar>()
i.value = 5
val p = i.ptr
}
```
|
I need to do something like this:
```
sizeof(int[width][height][8])
```
but unfortunately in c89 (the standard i have to use) this notation is forbidden, is there any way to do the same thing but using pointer notation?
Here's the error i get
It works fine in c99 but not in c89
|
You can write this instead:
```
(sizeof(int) * (width) * (height) * 8)
```
Make sure you put thesizeof(int)first to forcewidthandheightto be converted tosize_tand avoid a potential integer overflow onwidth * height * 8ifwidthandheighthaveinttype.
|
I have a code (not programmed by me) in which I have some parts where I have something like that:
```
#if CORE_DEBUG
ee_printf("State Bench: %d,%d,%d,%04x\n",seed1,seed2,step,crc);
#endif
```
My question is: what is the correct way to set up this environment variable?
EDIT: I am building the code withthisMakefi... |
It's a compilation flag, like-DCORE_DEBUG.
In some build environments you can enable/disable these as part of your build profile.
|
```
#include<stdio.h>
int main(void){
float a = 0.7;
if(a<0.7)
printf("C");
else
printf("c++");
}
```
I was going through a text book test your c skills by an Indian author. I found this question in a floating point problems chapter. I am comparing(0.7<0.7)which is false. So why is the out... |
Explanation:
0.7 is double constant (Default). Its binary value is
written in 64 bit.
Binary value of 0.7 = (0.1011 0011 0011 0011 0011 0011
0011 0011 0011 0011 0011)
Now here variable a is a floating-point variable while
0.7 is double constant. So variable a will contain only
32 bit value i.e.
```
a = 0.1011 0011 00... |
```
char port = 0xa5;
```
I wonder how the expression below evaluated according to standard.
```
(uint8_t) (~port) >> 4
```
Does left argument first converted to uint8_t and then promoted to int or vice versa?
|
Casts havehigher precedencethan bit shifts, so the cast should be executed first.
I also foundthis resourcewhich explains the need for the cast:
In this compliant solution, the bitwise complement of port is
converted back to 8 bits. Consequently, result_8 is assigned the
expected value of 0x0aU.uint8_t port = 0x5a;
... |
I got a structure like this in a header file :
```
typedef struct {
LIGNE *precedent;
PERSONNE individu;
LIGNE *suivant;
} LIGNE;
```
But when I compile, I got this error :
```
error: unknown type name ‘LIGNE’
LIGNE *precedent;
^~~~~
error: unknown type name ‘LIGNE’
LIGNE *suivant;
```
I don't un... |
As said in the commants and in theTomo Ceferin's answer, your compiler has no idea of whatLIGNEis until line 5.
One solution would be to typedef your structure before its declaration:
```
typedef struct S_LIGNE LIGNE;
struct S_LIGNE {
LIGNE *precedent;
PERSONNE individu;
LIGNE *suivant;
};
```
This way... |
I have a complex directory structure for a C project in which CMAKE governs which files are used for a certain project.
I tried using CMAKE extensions for VSCode, but it did not work very well.
Is there a way to tell VSCode which files exactly are used to be able to navigate through the code?
|
Open the Command Palette (F1orCtrl+Shift+P), look for "C/C++: Edit configurations (UI)", and add the desired folders under "Include path". This will allow Visual Studio Code's IntelliSense to know where your header files are located.
For an optimized experience, don't forget to also set up the path to the compiler, t... |
This question already has answers here:How do I properly compare strings in C?(11 answers)Closed2 years ago.
What will compare if two character arrays in C language are compared using "==" ?
The answer was Not Equal.
```
char string1 [] = "Hello";
char string2 [] = "Hello";
if (string1 == string2){
printf("Equal... |
What will compare if two character arrays in C language are compared
using "==" ?
Arrays base address will be compared.
If you want to compare the contents of the arrays you need to usestrcmp.
|
I want to align a text with the help of a variable using the.*format specifier.
Ideally I wanted a space of100length withSome Text Herewritten and then the|sign. But this doesn't seem to work.
```
#include <stdio.h>
int main()
{
int prec = 100; // Assume this value to be calculated somehow and not a constant
... |
The mistake is, that you try to do a precision like with a float (n decimal places). That won't work with a string.
You will need to do%*s, not%.*s
|
I have a complex directory structure for a C project in which CMAKE governs which files are used for a certain project.
I tried using CMAKE extensions for VSCode, but it did not work very well.
Is there a way to tell VSCode which files exactly are used to be able to navigate through the code?
|
Open the Command Palette (F1orCtrl+Shift+P), look for "C/C++: Edit configurations (UI)", and add the desired folders under "Include path". This will allow Visual Studio Code's IntelliSense to know where your header files are located.
For an optimized experience, don't forget to also set up the path to the compiler, t... |
Here's a test program I made.
```
#include <stdio.h>
int main(){
char arr[10];
int res=0, p = 2;
scanf(" %c",&arr[1]);
if(arr[1]>=48 &&arr[1]<=57){
res = arr[1] * p;
}
res = res+10;
printf("%d",res);
}
```
For input2the output is coming110,which would happen when inres = ar... |
If you read the character'2'into the array, which you do with"%c"(or" %c"), then the value arriving there will be the ASCII code of "2", not the value 2.
The ASCII for "2" is much higher than 2.
As Eugene mentions in a comment, the method to adapt to the offset is to subtract the difference of ASCII and "digit-value... |
On my machine, where anintis 32 bits, the following code :
```
int64_t m = (int64_t) 1 << 60;
int64_t n = (int64_t) 2048 * 2048 * 2048;
```
gives the mathematically expected results of 2^60 and 2^33 even though the standard seems to say that 1 and 2048 should be treaded as "int".
Should I consider that result as lu... |
Casting has precedence on many other operations, you can see the order herehttp://users.eecs.northwestern.edu/~wkliao/op-prec.htm
So you are actually working with int64_t all the time (as the name says, it's a signed integer with 64 bits) and that's why you don't overflow.
|
my string starts with abc or abcX, and ends with a number.
For example abc0159 or abcX0159.
I want to know if i can retrieve the number with sscanf, no matter if 'X' is there or not.
```
#include <stdio.h>
void main() {
char str1[14] = "abc1234567890";
char str2[15] = "abcX1234567890";
char num[11];
ssca... |
```
sscanf(str1, "%*[^0-9]%10s", num);
```
works with both strings, with*the value will be read but won't be written into variable, the10protects from buffer overflows.
|
So I wanted to write a function to calculate the Gcd or HCF of two numbers using the Divison method.This is my code:
```
#include <stdio.h>
#include <stdlib.h>
void gcd(int x, int y)
{
int g,l;
if (x >= y)
{
g = x;
l = y;
}
else
{
g = y;
l = x;
}
while... |
In:
```
g = l;
l = g % l;
```
the assignmentg = lloses the value ofgbeforeg % lis calculated. Change it to:
```
int t = g % l;
g = l;
l = t;
```
|
getline reads the input and further modifies it with the help of sscanf, how can I keep spaces in a variable st.m_Jmeno in the form of "something something"
```
while ( getline(&str, &capacity, stdin) != -1 )
{
sscanf(str,"%c %s %c %s", znak, st.m_Cislo,uvozovka, st.m_Jmeno);
...
```
|
You can use a%[pattern to get everything else in the line:
```
sscanf(str,"%c %s %c %[^\n]", &znak, st.m_Cislo,uvozovka, &tmp, st.m_Jmeno);
```
Note that this is (still) dangerous, in that it might overrun either string buffer if the input is too long.
|
Consider the following program:
```
int main()
{
int arr[8];
}
```
When compiling with gcc 9.3.0 on linux 20 the disassembly of the file looks like this at the beginning (this is NOT the whole assembly of the code above!):
```
┌ 72: int dbg.main (int argc, char **argv, char **envp);
│ ; var int[8] arr ... |
That's:
32 bytes for your array8 bytes for astack canaryA further 8 bytes to ensure16-byte stack alignment.
Total: 48 bytes.
|
How can I printf bytes of int when number 255 must be 255 not -1?
I can see that when I scanf 128 my program prints -128 but when I scanf 127 my program prints 127.
What can I do do printf 128 as 128.
```
#include <stdio.h>
union byte_set{
int x;
char tab[4];
};
int main(){
union byte_set... |
Change the type of thetabfield tounsigned char. Then they'll have the correct values.
```
union byte_set{
int x;
unsigned char tab[4];
};
```
|
```
#include <stdio.h>
int main(int argc, const char *argv[]) {
char name1[] = {'f','o','o'};
char name2[] = "foo";
printf("%s\n", name1);
printf("%s\n", name2);
return 0;
}
```
running the code above results in :
```
foox\363\277\357\376
foo
Program ended with exit code: 0
```
So, what's the difference ... |
name1is an array of three characters{'f', 'o', 'o'}.
name2is an array offourcharacters{'f', 'o', 'o', '\0'}.
printf("%s", ...)expects an array terminated with a null character. Becausename1isn't, you start dereferencing characters past the end of the array which can have the traditional undefined behavior.
|
I was trying a program which is requesting me to copy odd elements of one array to another array.This is the best logic that i can develeop until now. But it doesn't work properly. Could you please find my mistake and help me to correct it. Thanks in advance :)
```
#include<stdio.h>
int main() {
int array[10], odd... |
Furkan, change the last loop's iterating variable in oddArray from j to k:
```
for(int k=0;k<j;k++) {
printf("%d\n",oddArray[k]);
}
```
|
Closed. This question needsdetails or clarity. It is not currently accepting answers.Want to improve this question?Add details and clarify the problem byediting this post.Closed2 years ago.Improve this question
I am trying to write a functionisZero(int x)that returns 1 if x is 0, and returns 0 otherwise. How can I o... |
What about!!!x?
Look at following diagram for values zero and different than zero:
```
x == 0 | x <> 0
-------+-------
!x 1 | 0
!!x 0 | 1
!!!x 1 | 0
```
Isn't that what you want?
|
I am currently trying to multiply a__m512dvalue with a__m512ivalue. The__m512dvalue is ln(2), so the result is saved in another__m512dvariable.
However, I am not able to find any intrinsics for multiplying a double with an integer in avx512.
When I use the_mm512_castsi512_pdintrinsic on the__m512i, I get a wrong value... |
Thanks to @Peter Cordes for pointing out the mistake regarding the difference between casting and converting.
The following code allows the multiplication:
```
__m512d a;
__m512i b;
_mm512_muld_pd(a,_mm512_cvtepi64_pd(b));
```
|
So I have this part of code inside the main function:
```
char causatxt[10];
if(causa == CCOLA){
causatxt[0] = "COLA";
}
else if(causa == CMURO){
causatxt[0] = "CHOQUE";
}
printf("\n\nEl juego ha acabado por un '%s' con los siguientes datos:", causatxt);
```
The problem is that I... |
You can use strcpy from the string.h library
```
#include <string.h>
char a[100];
strcpy(a,"test");
```
|
```
#include <stdio.h>
#include <stdlib.h>
double cube(double num) {
return num * num * num;
}
int main(){
Answer(cube(3.0));
return 0;
}
void Answer(double cube()) {
printf("Answer: %.1f\n", cube());
}
```
If you try to run it, doesn't work, at least on my computer.
I tried to change some thi... |
I don't think your code compiles. Here's some quick fixes:
```
#include <stdio.h>
#include <stdlib.h>
void Answer(double); // forward declaration, you could also define Answer before main
double cube(double num) {
return num * num * num;
}
int main(){
Answer(cube(3.0));
return 0;
}
void Answer(dou... |
i am trying to make this basic program:
-It asks for an input
A : if it is a positive integer, thats good, and i can use that on the second part of the program.
B : if the input is not a positive integer, it will ask for a new input until it gets a positive integer.
```
#include <stdio.h>
#include <stdlib.h>
i... |
You have the loop condition backwards - you're supposed to continue looping as long as the input is not a positive integer:
```
do {
scanf("%d", &number);
}
while (number <= 0);
```
|
Closed. This question needsdetails or clarity. It is not currently accepting answers.Want to improve this question?Add details and clarify the problem byediting this post.Closed2 years ago.Improve this question
I am trying to write a functionisZero(int x)that returns 1 if x is 0, and returns 0 otherwise. How can I o... |
What about!!!x?
Look at following diagram for values zero and different than zero:
```
x == 0 | x <> 0
-------+-------
!x 1 | 0
!!x 0 | 1
!!!x 1 | 0
```
Isn't that what you want?
|
What will be the equivalent code in C for the following C++ code?
```
int main()
{
//...
int count=0;
fun(++count); //function call
//...
}
void fun(int &count) //function definition
{
//...
fun(++count); //Recursive Function call
//...
}
```
Herecountvariable is used to... |
You might use pointer:
```
int main()
{
int count = 0;
++count;
fun(&count); //function call
// ...
}
void fun(int *count) //function definition
{
// ...
++*count;
fun(count); //Recursive Function call
// ...
}
```
|
The function was written to free a list i created earlier...
```
rekord *felszab(rekord *el)
{
rekord *temp;
for(rekord *mozgo=eleje;mozgo=!NULL;mozgo=temp)
{
temp=mozgo->kov;
free(mozgo);
}
return el;
}
```
|
You call it without the prototype. Compiler assumes int as parameter and return value. Then it sees the definition having other types. Thus conflicting types
|
After running the following C program with Valgrind, it says thepackets.payloadvariable is uninitialised. But I cannot figure out why since I've already put "1234567890" inpackets.payload
```
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
typedef struct packet {
int payload_length;
char payload[1... |
A pointer toa string(a sequence of charactersterminated by null-character) must be passed toputs().
Yourpacket.payloaddoesn't contain terminating null-character, so you cannot use it forputs().
You can useprintf()with specifying length to print to print that:
```
printf("%.*s\n", 10, packet.payload);
```
|
This question already has answers here:How to read from stdin with fgets()?(6 answers)Closed2 years ago.
```
void name(record *el)
{
char k[100];
printf("Name: ");
fgets(k,100,stdin);
printf("\n");
}
```
I'm trying to write a function that reads a line from console and then searches for it in a list.... |
You probably read an integer before calling the function and the '\n' was left on the input stream.
Try calling the function as the first command you do in main and you will see that it works.
If you read a number right before the call with scanf for example, you could add a '\n' in the parameter string before calli... |
What will be the equivalent code in C for the following C++ code?
```
int main()
{
//...
int count=0;
fun(++count); //function call
//...
}
void fun(int &count) //function definition
{
//...
fun(++count); //Recursive Function call
//...
}
```
Herecountvariable is used to... |
You might use pointer:
```
int main()
{
int count = 0;
++count;
fun(&count); //function call
// ...
}
void fun(int *count) //function definition
{
// ...
++*count;
fun(count); //Recursive Function call
// ...
}
```
|
The function was written to free a list i created earlier...
```
rekord *felszab(rekord *el)
{
rekord *temp;
for(rekord *mozgo=eleje;mozgo=!NULL;mozgo=temp)
{
temp=mozgo->kov;
free(mozgo);
}
return el;
}
```
|
You call it without the prototype. Compiler assumes int as parameter and return value. Then it sees the definition having other types. Thus conflicting types
|
```
printf("%i\n",2&2==2);
```
This should print out a 1 but I get a 0, why is this?
```
int ans=2&2;
printf("%i\n",ans==2);
```
This prints a 1, how come the first way does not work?
This is the case with if statements as well
|
The order of operations is different than you think it is. A correct way to write it in a single line would be:
```
printf("%i\n", (2 & 2) == 2); // Prints 1
```
|
Closed.This question isnot reproducible or was caused by typos. It is not currently accepting answers.This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may beon-topichere, this one was resolved in a way less likely to help future readers.Closed2 years ago.Improve... |
When you rungcc thatfile.c, this compiles your C code. This creates another file, normally calleda.out, which you have to execute. You can do this by./a.out.
|
This was asked in a written test of an interview :
Question: write a function pointer prototype which takes three integer pointers as arguments and returns character pointer.
My answer:
```
char (*funct_ptr) (int *a, int *b, int *c);
```
This was marked wrong. Can anyone please help me with the right answer to this... |
Your prototype is declared to return a character, not a character pointer.
To make the returned thing to a pointer, add*.
```
char* (*funct_ptr) (int *a, int *b, int *c);
```
|
```
int main() {
x=5;
printf("%d",x+3);
}
```
xcould be either5or8after this example (I know that the output on the screen would be 8.)
|
The value at the address ofxremains unchanged in this example. Inside theprintf, we first get the value at the address ofxand then add it to 3 and output it to the screen.
This is why we use statements likex=x+3to change the value.
|
I'm working in a project using SIMD instructions and I don´t know exactly how to create a vector aligned in memory. I´m using packets of 128 bits (4 floats per packet).
```
float redVector[vectorSize];
```
I saw many places where people use structures and the property attribute... Any explanation is welcomed. Thank ... |
Assuming your compiler supports C11, you can use_Alignas():
```
_Alignas(16) float redVector[vectorSize];
```
Some people prefer the more C++ compatible
```
#include <stdalign.h>
alignas(16) float redVector[vectorSize];
```
Pre C11 gcc can use
```
float redVector[vectorSize] __attribute__((__aligned__(16)));
```... |
I'm trying to read the next new line in a text file and place it into an array, I was able to place the first line to an array. But I want to place each line in the text file into in separate arrays, is there a way to jump to the next line in the text file?
Code:
```
while(((ch = getc(file1))!= '\n') && (i < 30))
{
... |
Do something like this:
```
while (fgets(buf, MAX_LEN - 1, fp))
{
printf("%s", buf);
}
```
where buf is some char array, MAX_LEN is the maximum expected line length and fp is the file pointer. The function fgets reads until either (n-1) characters are read, the newline character is read, or the end of file is re... |
Closed. This question isopinion-based. It is not currently accepting answers.Want to improve this question?Update the question so it can be answered with facts and citations byediting this post.Closed2 years ago.Improve this question
I have an algorithm that is written in C.
I want to use Spark to run it on a cluste... |
Here is a nice article from databricks on how we can run c and c++ codes in apache spark.
https://kb.databricks.com/_static/notebooks/scala/run-c-plus-plus-scala.html
After moving the c/c++ codes to the underlying distributed file system, You can compile the code and run on spark worker nodes.
|
Anytime I clear build folder in flutter (either withflutter cleanor manually), my jni folder rebuilds (~40 mins). Is that possible to compile library to some binary, and use it from android without breaking any interfaces and functionality?
P.S. My library consists of many folders and contains .mk, .c, .cpp, .h files... |
Is that possible to compile library to some binary, and use it from android without breaking any interfaces and functionality?
Of course yes. Build you libraries like shared.soor static.aand use them like prebuilts. Here the example how to use native prebuilt libraries:How to link .a to .so and create new .so for and... |
You should have a condition which should evaluate to true or false in order for anifstatement to work. I don't understand howp=fopen("test.txt", "r")part of the following code evaluates to true or false since it only contains an assignment operator=and not a==operator.
```
#include <stdio.h>
int main()
{
FILE *p;
... |
From theC11spec, chapter 6.5.16,
" An assignment expression has the value of the left operand after the assignment [....]"
So basically, you code is same as
```
p=fopen("test.txt","r");
if(p) { // or, if (p != NULL) for ease of understanding
// do something
}
```
|
I have 2 structures:
```
typedef struct
{
int a;
} S1;
typedef struct
{
S1[0xff];
} S2;
```
Let's say I only require the element 0xf0 out of S2->S1, and the rest will be zero or whatever, unimportant.
I fill the struct like such:
```
S2 g_s2[] = {
// 0x00
{ 0 },
// 0x01
{ 1 }
}
```
Is there some way to pad t... |
```
S2 g_s2[] = { [0xf0] = 12 };
```
Here, we are initializing only0xf0th element to 12, remaining elements of the array will be zero.
|
Closed. This question needsdetails or clarity. It is not currently accepting answers.Want to improve this question?Add details and clarify the problem byediting this post.Closed2 years ago.Improve this question
So I'm doing CS50 and struggling with an error that occurs when I include the following two lines:
```
if ... |
No you can not declare variable in an if statement. But if you want your variable in a local scope you can create a block and declare your variable, initialize it and use. We have to use <= for checking less than or equal to instead of =<
example:
```
{
int i =5,number=10;
if(i < number-1)
{
//Add your code
... |
I am running this c program in gcc.
The below works for one variable.
```
#define dataBlk_tx0 ((volatile unsigned int *) 0x20000ACB)
```
But if I want to create an array and write to it how would I do this, this array needs to be defined before main?
```
#define dataBlk_tx0 ((volatile unsigned int * x[8]) 0x20000AC... |
If you want to read or write directly to that address and memory, you can do it like this:
InitializedataBlk_tx0as a pointer to the specific memory locationAccess that memory through the pointer.
```
volatile unsigned int * dataBlk_tx0 = (unsigned int *)0x20000ACB;
int main () {
dataBlk_tx0[0] = 5;
return 0... |
You should have a condition which should evaluate to true or false in order for anifstatement to work. I don't understand howp=fopen("test.txt", "r")part of the following code evaluates to true or false since it only contains an assignment operator=and not a==operator.
```
#include <stdio.h>
int main()
{
FILE *p;
... |
From theC11spec, chapter 6.5.16,
" An assignment expression has the value of the left operand after the assignment [....]"
So basically, you code is same as
```
p=fopen("test.txt","r");
if(p) { // or, if (p != NULL) for ease of understanding
// do something
}
```
|
I have 2 structures:
```
typedef struct
{
int a;
} S1;
typedef struct
{
S1[0xff];
} S2;
```
Let's say I only require the element 0xf0 out of S2->S1, and the rest will be zero or whatever, unimportant.
I fill the struct like such:
```
S2 g_s2[] = {
// 0x00
{ 0 },
// 0x01
{ 1 }
}
```
Is there some way to pad t... |
```
S2 g_s2[] = { [0xf0] = 12 };
```
Here, we are initializing only0xf0th element to 12, remaining elements of the array will be zero.
|
Closed. This question needsdetails or clarity. It is not currently accepting answers.Want to improve this question?Add details and clarify the problem byediting this post.Closed2 years ago.Improve this question
So I'm doing CS50 and struggling with an error that occurs when I include the following two lines:
```
if ... |
No you can not declare variable in an if statement. But if you want your variable in a local scope you can create a block and declare your variable, initialize it and use. We have to use <= for checking less than or equal to instead of =<
example:
```
{
int i =5,number=10;
if(i < number-1)
{
//Add your code
... |
I am running this c program in gcc.
The below works for one variable.
```
#define dataBlk_tx0 ((volatile unsigned int *) 0x20000ACB)
```
But if I want to create an array and write to it how would I do this, this array needs to be defined before main?
```
#define dataBlk_tx0 ((volatile unsigned int * x[8]) 0x20000AC... |
If you want to read or write directly to that address and memory, you can do it like this:
InitializedataBlk_tx0as a pointer to the specific memory locationAccess that memory through the pointer.
```
volatile unsigned int * dataBlk_tx0 = (unsigned int *)0x20000ACB;
int main () {
dataBlk_tx0[0] = 5;
return 0... |
I'd like to subscript an array literal at the point of definition, since I don't need the array after that initial access:
```
int func(int index) {
return {1, 2, 3, 4, 5}[index];
}
```
Note: the array elements are more complex than this example. Also I'm omitting boundary checks. I'm simply curious whether the C... |
You can use the so-calledcompound literals:
```
#include <stdio.h>
int main(void) {
printf("%d\n",
(int[]){1,2,3,4,5}[2]);
return 0;
}
```
Refer to C standard draft section6.5.2.5 Compound Literals
|
How can i do this senquence without a recursive function
the mean of ( ^ ) is && in this question
in rec i wrote but without i cant get it right
```
Sn(int n)
{
if (n <= 2)
return 1;
if (n % 2 == 0)
return ex4_rec(n - 1) + ex4_rec(n - 2) + ex4_rec(n - 3);
else
ret... |
No recursion:
```
#include <stdio.h>
int foo(int n) {
long long s0 = 1, s1 = 1, s2 = 1;
printf("1, 1, 1");
for (int k = 3; k < n; k++) {
long long next;
if (k % 2 == 0) {
next = s2 + s1 + s0;
} else {
next = s2 - s0;
}
printf(", %lld", next)... |
I'm trying to do I/O redirection in the open shell on repl.it. Taking the input from one file to run through the program. Outputting to a new file but nothing shows up? I'm only used to doing it from Windows using the CMD.
Shell:
```
~/maybe-lab6and7$ clang-7 -pthread -lm -o main main.c < address.txt >
open.txt
~/m... |
After compiling and linking your program, if no compile problems and no link problems occur, you will have an executable in the current directory. (Lets say the executable is named:main.)
Then, after changing the program permissions somainis executable,you can execute the program similar to:
```
./main < sourcedat... |
Consider a structure with the following data members:
```
struct Data
{
unsigned int count;
const char *Name;
};
```
A variable of typestruct Datais created later in the code:
```
PERSISTENT(struct Data log);
```
wherePERSISTENT()maps a variable to the battery-backed SRAM memory space.
WhenNameis later a... |
The string literals will be stored in the FLASH memory where the.rodatasegment is located.
|
Greeings,
I have a rather peculiar question.
I'm currently coding in C and I wanted to implement a shortcut command for the user (CTRL + C) that can be used at any moment during an .exe being run and I have no idea on how to make it, without having to resort toscanf().
I want the user to be able to just cancel whate... |
you can use signals for that .For example you can create a function where there put what ever you want to do lets say :
```
void action(int handle){
//do something here ,put here your code for this user
}
```
and in your main function you can handle ctr+c like that :
```
signal(SIGINT,action);
```
|
This code will take the user input and use it to build blocks.
Entering a number between 1 and 8 it should print something like this.
```
###
###
###
```
I want it to take the integer from the user and instead print the blocks like this. Say the user enters the number 5. Currently you'll get this.
```
#####
#####
#... |
changefor (int j = 0; j < n; j++)
tofor (int j = 0; j <= i; j++)
The number of#will increase with each loop asiincreases
|
Imagine I have a program with a main function that creates several threads. In each thread I redirect theCTRL + Cinterruption (SIGINT) to afunctionAviasignal(SIGINT, functionA)and in the main process I redirect the same interruption to afunctionB(signal(SIGINT, functionB).
When the program is running and the interrup... |
Signal handler action (SIG_IGN, SIG_DFL, or a handler function) is a per-process property, not a per-thread property.
This means that if say different threads usesigaction()to set the same signal action, then the latest one wins.
Furthermore, if you have multiple threads that do not block the signal, the kernel simp... |
Closed. This question needsdetails or clarity. It is not currently accepting answers.Want to improve this question?Add details and clarify the problem byediting this post.Closed2 years ago.Improve this question
I need to send a signed short integer but thesendtofunction requires me to give a char buffer.
The buffer:... |
Actually, this is the declaration of sendto():
```
ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,
const struct sockaddr *dest_addr, socklen_t addrlen);
```
The buffer is of type void* so you can pass it a pointer to any type of variable.
In your case:
```
short your_variable;
... |
```
int *f1(int i) {
return &i;
}
int main(void) {
int x = 10;
int *p = f1(x);
printf("%d\n", *p);
printf("%d\n", *p);
return 0;
}
```
Even if I write
```
int *p;
p = f1(10);
```
This still gives segmentation fault.
Can somebody explain, Why is the code not working ?
|
You're returning the address ofi, which only exists untilf1returns. Oncef1returns,iceases to exist, and the pointer you created is no longer usable. Dereferencing it is undefined behaviour.
Maybe you wanted
```
#include <stdio.h>
#include <stdlib.h>
int *f1(int i) {
int *p = malloc(sizeof(int));
*p = i;
re... |
Using '-' in an identifier cause the error:
```
‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘-’ token
```
Why this happenned?
|
'-' is not used as token in c standard.
Your premise is wrong. - is used as a token. Quote from C11 standard draft:
6.4 Lexical elementsSyntaxtoken:
...
punctuator
6.4.6 PunctuatorsSyntaxpunctuator:
... - ...
Ellipses represent an omission.
When will '-' character be represented in an identifier?
Never... |
I have the following code:
```
#define MAX_NAME_LEN 15
#define PRINT_CELL(x) \
printf("|%" #MAX_NAME_LEN "s|", #x);
```
When I try to compile, I get the following error:
```
main.c:9:21: error: '#' is not followed by a macro parameter
9 | #define PRINT_CELL(x) \
| ^
```
I'm not qu... |
#MAX_NAME_LENis illegal becauseMAX_NAME_LENis not an identifier in the replacement list of thePRINT_CELL(x)macro. Use the following, instead:
```
#define PRINT_CELL(x) printf("|%*s|", MAX_NAME_LEN, #x);
```
|
i'm trying to read values from a txt file.
the following code works well, but it only print the values to the standard output, i don't know how to store those values in a variable.
Thankyou in advance.
```
char *value = NULL;
double Training[401], Test[50];
int i=0;
size_t line_buf_size = 0;
while(i<4)
{
... |
I think the problem you are facing is storing your "value" variable (type: char *) into "Training[i]" (type: double).
You need to convert from char * to double:https://stackoverflow.com/a/10075336/7440867.
|
I am trying to build a C program in Eclipse CDT that usesOpusandAlsalibraries. I normally compile the program in command line as follows:
```
cc prog.c -o prog.exe -lopus -lasound
```
but I couldn't achieve the same in eclipse CDT. I add the linker flags at
```
Project > Properties > C/C++ Build > Settings > Tool S... |
Don't add libraries as-lopusunderMiscellaneous. Rather, add them underProject > Properties > C/C++ Build > Settings > Tool Settings > GCC C Linker > Libraries, in theLibraries (-l)listbox. In there, just put the name of the library without the-l.
Alternatively, you can list your libraries inProject > Properties > C/C... |
```
int *f1(int i) {
return &i;
}
int main(void) {
int x = 10;
int *p = f1(x);
printf("%d\n", *p);
printf("%d\n", *p);
return 0;
}
```
Even if I write
```
int *p;
p = f1(10);
```
This still gives segmentation fault.
Can somebody explain, Why is the code not working ?
|
You're returning the address ofi, which only exists untilf1returns. Oncef1returns,iceases to exist, and the pointer you created is no longer usable. Dereferencing it is undefined behaviour.
Maybe you wanted
```
#include <stdio.h>
#include <stdlib.h>
int *f1(int i) {
int *p = malloc(sizeof(int));
*p = i;
re... |
Using '-' in an identifier cause the error:
```
‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘-’ token
```
Why this happenned?
|
'-' is not used as token in c standard.
Your premise is wrong. - is used as a token. Quote from C11 standard draft:
6.4 Lexical elementsSyntaxtoken:
...
punctuator
6.4.6 PunctuatorsSyntaxpunctuator:
... - ...
Ellipses represent an omission.
When will '-' character be represented in an identifier?
Never... |
I have the following code:
```
#define MAX_NAME_LEN 15
#define PRINT_CELL(x) \
printf("|%" #MAX_NAME_LEN "s|", #x);
```
When I try to compile, I get the following error:
```
main.c:9:21: error: '#' is not followed by a macro parameter
9 | #define PRINT_CELL(x) \
| ^
```
I'm not qu... |
#MAX_NAME_LENis illegal becauseMAX_NAME_LENis not an identifier in the replacement list of thePRINT_CELL(x)macro. Use the following, instead:
```
#define PRINT_CELL(x) printf("|%*s|", MAX_NAME_LEN, #x);
```
|
i'm trying to read values from a txt file.
the following code works well, but it only print the values to the standard output, i don't know how to store those values in a variable.
Thankyou in advance.
```
char *value = NULL;
double Training[401], Test[50];
int i=0;
size_t line_buf_size = 0;
while(i<4)
{
... |
I think the problem you are facing is storing your "value" variable (type: char *) into "Training[i]" (type: double).
You need to convert from char * to double:https://stackoverflow.com/a/10075336/7440867.
|
I am trying to build a C program in Eclipse CDT that usesOpusandAlsalibraries. I normally compile the program in command line as follows:
```
cc prog.c -o prog.exe -lopus -lasound
```
but I couldn't achieve the same in eclipse CDT. I add the linker flags at
```
Project > Properties > C/C++ Build > Settings > Tool S... |
Don't add libraries as-lopusunderMiscellaneous. Rather, add them underProject > Properties > C/C++ Build > Settings > Tool Settings > GCC C Linker > Libraries, in theLibraries (-l)listbox. In there, just put the name of the library without the-l.
Alternatively, you can list your libraries inProject > Properties > C/C... |
i'm trying to read values from a txt file.
the following code works well, but it only print the values to the standard output, i don't know how to store those values in a variable.
Thankyou in advance.
```
char *value = NULL;
double Training[401], Test[50];
int i=0;
size_t line_buf_size = 0;
while(i<4)
{
... |
I think the problem you are facing is storing your "value" variable (type: char *) into "Training[i]" (type: double).
You need to convert from char * to double:https://stackoverflow.com/a/10075336/7440867.
|
I am trying to build a C program in Eclipse CDT that usesOpusandAlsalibraries. I normally compile the program in command line as follows:
```
cc prog.c -o prog.exe -lopus -lasound
```
but I couldn't achieve the same in eclipse CDT. I add the linker flags at
```
Project > Properties > C/C++ Build > Settings > Tool S... |
Don't add libraries as-lopusunderMiscellaneous. Rather, add them underProject > Properties > C/C++ Build > Settings > Tool Settings > GCC C Linker > Libraries, in theLibraries (-l)listbox. In there, just put the name of the library without the-l.
Alternatively, you can list your libraries inProject > Properties > C/C... |
I have this line of code that I don't understand.
```
char string[100];
while(string[i])
{
//statements
i++;
}
```
|
This:
```
while (string[i])
{
//statements
i++;
}
```
is strictly equivalent to this:
```
while (string[i] != 0)
{
//statements
i++;
}
```
In C an expression if considered as false if its value is 0, and true if its value is different from zero.
You could also write this
```
if (Foo)
...
```
inste... |
I installed MinGW, and i wrote the following code test
```
#include <stdio.h>
int main() {
#if defined(__WIN32__)
printf("hello win.");
#else
printf("hello unix.");
#endif
return 0;
}
```
then compiled and run.
```
V002294@DESKTOP-A0H4TOJ /c/Users/V002294
$ gcc test.c -o test
V002294@DESKTOP-A0H4TOJ /... |
__WIN32__must be defined given the result your getting.
It looks like when you rungccit's using MinGW's gcc.
Check yourPATHenvironment variable (echo $PATH) to see if the MinGW location is in it before the Linux version. Or just runwhich gccto see which one is being used.
Or maybe you don't have any other gcc insta... |
I need to change the config bits in a EZBL bootloader project.
I'm able to compile it, with version 2.11 and MPLAB X ide 5.4
The problem is that config bits are fully wrong, and if i modify them in mplab ide they are gone to the old value after recompile. That means that config bits are set programally or set in pro... |
You can do it in your source code like this:
```
/*Config1*/
#pragma config FEXTOSC = OFF
#pragma config RSTOSC = HFINT32
#pragma config CLKOUTEN = OFF
...
```
Have a look in the filepic_chipinfo.htmlwhich configuration bits are handeld in your controller
|
I've use cURL command-line tool with --libcurl and a url of mine(the url works in normal C), however I get the error "curl.h" does not exist, although it is in the same directory. I can't figure out how to include headers in emscripten. All of the supposed documentation on this usually ends up being about something el... |
I figured it out, I was being dumb
|
While getting familiarized with the operating systems course I'm taking, I came accross this code and I'm having trouble understanding the second part of the print (%s - &i).
```
unsigned int i = 0x00646c72;
printf("H%x Wo%s", 57616, &i);
```
This yields the output of:
```
He110 World
```
First part is just hex re... |
The address didn't end up being 'rld'.
It works because %s expects a pointer to char (pointing to a null-terminated string of char). And because &i points to i, which is the bytes 0x72, 0x6C, 0x64, 0x00. Which is the null-terminated string of ascii character codes 'r', 'l', 'd'.
|
```
for (j = 0; j < 900; j++)
{
fptext = fopen("..\\n_file_list[j]", "w");
fseek(fptext, 0, SEEK_END);
size = ftell(fptext);
buffer_text = malloc(size + 1);
memset(buffer_text, 0, size + 1);
fseek(fptext, 0, SEEK_SET);
fread(buffer_text, size, 1, fptext);
}
```
n_file_list has 900 txt... |
I think you made a mistake here :
```
fptext = fopen("..\\n_file_list[j]", "w");
```
This line should be :
```
fptext = fopen(n_file_list[j], "w");
```
|
Closed. This question needsdetails or clarity. It is not currently accepting answers.Want to improve this question?Add details and clarify the problem byediting this post.Closed2 years ago.Improve this question
So I have two unsigned 32bit ints, I need to find the difference between them in bytes.
Essentially the ta... |
Below is a function for calculating how many bytes an unsigned integer needs. Just use it on the two numbers and calculate the difference.
Edit: Thanks to Eric Postpischil for his patience with my sloppiness.
```
#include <limits.h>
int ByteCount(unsigned int n)
{
int result = 0;
while (n != 0) {
... |
So I wanto to compile a program that has included these headers:
```
#include <stdio.h>
#include "teclas_tictac.h"
```
The headerteclas_tictac.hhas prototypes for functions inteclas_tictac.cfile.
How do I do that?
I usually dogcc myprogram.c -o myprogram.
Thanks
|
Not to get too technical, but the function implementations is what needs to be assembled, converted to object code and finally linked, the header file is not used directly in the compilation process, its contents are simply copied to where you use the#includedirective.
So what you need for the compilation process is ... |
I have a string representing a number, with some digits "hidden" behind the symbol '!'.
I would like to generate and print all possible numbers obtained by replacing the '!' by '1' or '2'.
For instance:
```
INPUT: 12!21!
OUTPUT: 121211
121212
122211
122212
```
I would like to solve this pr... |
Let me write this in pseudo-code:
```
void combination(input_array){
boolean bExclamation_found = (index("!",input_array)>-1);
if bExclamation_found
then printout(input_array)
else {
combination(replace_one_exclamation(input_array, "1"));
combination(replace_one_exclamation(input_array, "2"));
}
```
Good luck
|
I am trying to understand why the output of this code would be 7 11 and I am lost. What isptr[1][2]andptr[2][1]referring to?
```
#include <stdio.h>
#define SIZE 25
int main()
{
int a[SIZE];
int *ptr[5];
for (int i = 0; i < SIZE; i++){
a[i] = i;
} //has values 0-24
ptr[0]=a; /... |
ptr[1] = ptr[0]+5which refer toa[0+5]=a[5]
ptr[2] = ptr[1]+5which refer toa[5+5]=a[10]
so
prt[1][2]should bea[5+2]which isa[7]= 7
prt[2][1]should bea[10+1]which isa[11]= 11
|
While getting familiarized with the operating systems course I'm taking, I came accross this code and I'm having trouble understanding the second part of the print (%s - &i).
```
unsigned int i = 0x00646c72;
printf("H%x Wo%s", 57616, &i);
```
This yields the output of:
```
He110 World
```
First part is just hex re... |
The address didn't end up being 'rld'.
It works because %s expects a pointer to char (pointing to a null-terminated string of char). And because &i points to i, which is the bytes 0x72, 0x6C, 0x64, 0x00. Which is the null-terminated string of ascii character codes 'r', 'l', 'd'.
|
```
for (j = 0; j < 900; j++)
{
fptext = fopen("..\\n_file_list[j]", "w");
fseek(fptext, 0, SEEK_END);
size = ftell(fptext);
buffer_text = malloc(size + 1);
memset(buffer_text, 0, size + 1);
fseek(fptext, 0, SEEK_SET);
fread(buffer_text, size, 1, fptext);
}
```
n_file_list has 900 txt... |
I think you made a mistake here :
```
fptext = fopen("..\\n_file_list[j]", "w");
```
This line should be :
```
fptext = fopen(n_file_list[j], "w");
```
|
Closed. This question needsdetails or clarity. It is not currently accepting answers.Want to improve this question?Add details and clarify the problem byediting this post.Closed2 years ago.Improve this question
So I have two unsigned 32bit ints, I need to find the difference between them in bytes.
Essentially the ta... |
Below is a function for calculating how many bytes an unsigned integer needs. Just use it on the two numbers and calculate the difference.
Edit: Thanks to Eric Postpischil for his patience with my sloppiness.
```
#include <limits.h>
int ByteCount(unsigned int n)
{
int result = 0;
while (n != 0) {
... |
So I wanto to compile a program that has included these headers:
```
#include <stdio.h>
#include "teclas_tictac.h"
```
The headerteclas_tictac.hhas prototypes for functions inteclas_tictac.cfile.
How do I do that?
I usually dogcc myprogram.c -o myprogram.
Thanks
|
Not to get too technical, but the function implementations is what needs to be assembled, converted to object code and finally linked, the header file is not used directly in the compilation process, its contents are simply copied to where you use the#includedirective.
So what you need for the compilation process is ... |
I have a string representing a number, with some digits "hidden" behind the symbol '!'.
I would like to generate and print all possible numbers obtained by replacing the '!' by '1' or '2'.
For instance:
```
INPUT: 12!21!
OUTPUT: 121211
121212
122211
122212
```
I would like to solve this pr... |
Let me write this in pseudo-code:
```
void combination(input_array){
boolean bExclamation_found = (index("!",input_array)>-1);
if bExclamation_found
then printout(input_array)
else {
combination(replace_one_exclamation(input_array, "1"));
combination(replace_one_exclamation(input_array, "2"));
}
```
Good luck
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.