Anonymous
what can that do ?
Same thing. But use glob
Anonymous
they won't scan and add file with .h
Anonymous
why I can't change like that
Anonymous
target_link_libraries(main ${PROJECT_SOURCE_DIR}/libs/libglfw3.a ${PROJECT_SOURCE_DIR}/libs/libjsoncpp.a ${PROJECT_SOURCE_DIR}/libs/libjsoncpp.dll.a opengl32)
Anonymous
link_directories(${PROJECT_SOURCE_DIR}/libs) target_link_libraries(main libglfw3.a libjsoncpp.a libjsoncpp.dll.a opengl32)
Jagadeesh
int funct1(int a) { if(a) return funct1(--a)+a; else return 0; } int main() { int a=7; printf("%d",funct1(a)); return 0; }
Jagadeesh
can anyone explain how it's printing 21
Anonymous
#include <iostream> int main() { int a = 7; a = (--a) + a; printf("%d", a); }
Anonymous
it does work
Anonymous
when --a
Anonymous
a become 6(both two)
Anonymous
you can have a try
\Device\NUL
a become 6(both two)
Ow, my bad, srry i miss the point
I use Arch
int funct1(int a) { if(a) return funct1(--a)+a; else return 0; } int main() { int a=7; printf("%d",funct1(a)); return 0; }
return fuct1 (--a) + a; a = 7; return funct1 (6) + 6; // 6 return funct1 (5) + 5 + 6; // 11 return funct1 (4) + 4 + 5 + 6; // 15 ... return funct1 (0) + 0 + 1 + 2 + 3 + 4 + 5 + 6; // 21 And recursion will be stopped because 0 will be converted to false.
\Device\NUL
6 + 5 + 4 + 3 + 2 + 1 + 0
olli
Intel documentation and programming guide for x86 development
which calling convention does Intel define? The last time I checked the SDM it did not define any calling convention (apart from enclave operations). Maybe I should take another look at it.
Ammar
Intel documentation and programming guide for x86 development
I haven't finished to read all of those. But I think the calling convention is defined per ABI.
Ammar
Or is this the same with context switch that the OS is obliged to follow?
Anonymous
Hello, I am Hossein, a doctoral researcher at the University of Padova, Italy. With the aid of the University of Padova and NXP Semiconductor, we started a project similar to the Unreal Engine for programming micro-controllers in Italy. Are you interested in helping us with it?
Anonymous
How are you doing
Anonymous
How are you doing today
Anonymous
Ok were are you located in
Ammar
Intel documentation and programming guide for x86 development
Ok, you wrote: > it is entirely unrelated to calling conventions But what exactly is that? Those register saving and restoring rules are calling convention. It differs per ABI.
Ammar
I don't understand
Which part? Please be specific.
Anonymous
Abuja Nigeria
Anonymous
I live in Abuja
I don't
why do we need two pointers here(*(uintptr_t*))?
Anton
Hi everyone. I need help with static variable that is written in C. The purpose of the function is to concatenate "abc" string twice to static variable store. On second foo() call I remove the value that was written in the previous call. I already found out that you cannot check whether the variable was initialized or not. I need some work around here, preferably with temporary string in init. Second static variables, global variables, and sentinel values are not allowed. Desired output: "abc\nabcabc\n". Current output "abc\nabc\n". void init(char **store) { (*store) = (char *)malloc(sizeof(char)); (*store)[0] = '\0'; } int foo() { static char *store; char *string; string = "abc"; init(&store); store = strcat(store, string); printf("%s\n", store); } int main() { foo(); foo(); }
Anton
Why would you do that?
Why would I do what?
Ammar
Practically, you should also free() anything you malloc()'ed.
Anton
There are several things go wrong with your code. 1) You only allocate sizeof(char) of memory with malloc(), but you use more. 2) You are leaking memory by overwriting the old pointer returned by the malloc for the second foo() call. 3) Your foo() is defined as a function that returns an int, but it does not return anything.
1) Yes, it is correct. My bad. 2) Should I free it before overwriting? 3) Yes, I should have defined it as void. The code that I sent is basically a small snippet from a big function. I need to fix only the logic that I described above.
Ammar
I'll fix the code and come back to it.
Ok, you're good. For what it's worth, I fixed your code. I don't think there is a chance to call free() here. But let's assume memory leak is acceptable for this case. #include <stdio.h> #include <stdlib.h> #include <string.h> void init(char **pp) { if (*pp != NULL) { *pp = realloc(*pp, strlen(*pp) * 2 + 1); } else { *pp = malloc(4); (*pp)[0] = '\0'; } } void foo(void) { static char *store; init(&store); strcat(store, "abc"); printf("%s\n", store); } int main(void) { foo(); foo(); return 0; }
Ammar
why do we need two pointers here(*(uintptr_t*))?
What is even the context of your question? Why do we need? I don't know, why would you write that?
I don't
ive already understood, ty
Diego
I want to program a serial terminal with a easy user interface for Windows. I never used C++ before. I was checking and Qt could be a good option for it. What do you think?
Ashish
hello guys ,can anyone please help me using graphics.h in code block its kinda urgent
Anonymous
Hi i need help fast
Anonymous
How is the programme structure for creating a tree that has n high and in the right ir is written the numbers from 1 to the file number
Anonymous
And in the left the letters
Anonymous
Its form is a trangule
Anonymous
Example: n=3 1 A12 BC123
YVEF
Hi. Is anybody tried to setup Boost.TestExplorer in VSCode?
klimi
warning: control reaches end of non-void function [-Wreturn-type] 18 | }
Juli
Can anyone help me
Juli
#include <iostream> using namespace std; void main (void) { static int N = 10; int counter, sum, number; cout << " Enter a Positive Integer smaller" << " or equal to 10 (the counter) "; cin >> counter; cout << endl; sum = 0; do { cout << " Enter a Positive Integer " ; cin >> number; cout << endl; sum = sum + number; counter ++; } while ( counter < N ); cout << " The sum of the digits you have entered is = " << sum << endl; if ( ( sum % 2 ) == 0 ) cout << " " << sum << " is divisible by 2 " << endl; else cout << " " << sum << " is not divisible by 2 " << endl; // note here no need of return anything // because the return type of ' main ' is ' void ' } // end of main
Juli
Basiclly i nedd to replace the do {  } while ( ) loop with a for loop
Anonymous
Basiclly i nedd to replace the do {  } while ( ) loop with a for loop
Just change your do while to a for loop like this: for(; counter < N; ++counter)
\Device\NUL
whats the difference in C?
func(); takes unspecified number of arguments. func(void); takes zero argument.
Sebas Tian
func(); takes unspecified number of arguments. func(void); takes zero argument.
then can i give any args in a func declared as func() ?
Anonymous
using void as function parameter in C++ is redundant. func(void) is same as func() . But in C they're different. Also why not !(sum % 2) ?
It means the same in C as well given that it occurs in the definition and not the declaration. So void func(void) {} is the same as void func(){} in C just like in C++.
Anonymous
Having said that, it is always a better idea to use void in C when you want to convey that a function has an empty parameter list.
соня
Hi guys :) I have to create accdb using ADO with c++ #import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "adoEOF") #include <iostream> using namespace std; int main(){ CoInitialize(NULL); setlocale(LC_ALL, "Russian"); try { _bstr_t scon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\DB\\CPP\\test.accdb"; _ConnectionPtr con("ADODB.Connection"); con.CreateInstance(__uuidof(Connection)); con->Open(scon, (_bstr_t)"", (_bstr_t)"", adConnectUnspecified); _bstr_t strCmd = "INSERT INTO Employees(EmployeeID, FirstName, LastName, HireDate, City, Country) VALUES(10, 'Mary', 'Williams', '15/4/1993 12:00:00', 'New York', 'USA')"; con->Execute(strCmd, NULL, adCmdText); con->Close(); } catch (_com_error& e) { cout << e.Description(); } ::CoUninitialize(); } Thats what I've done, but file test.accdb is not created. Works catch with mistake, that he cant find C:\DB\CPP\test.accdb Can someone help? 🥺
Anonymous
Basiclly i nedd to replace the do {  } while ( ) loop with a for loop
For loop need three things in its condition parenthesis i.e (Int i , i>=10,i++)
Anonymous
#include <iostream> using namespace std; int main () { static int N = 10; int counter, sum, number; cout << " Enter a Positive Integer smaller" << " or equal to 10 (the counter) "; cin >> counter; cout << endl; sum = 0; for(int i;i<10;i++) { cout << " Enter a Positive Integer " ; cin >> number; cout << endl; sum = sum + number; counter ++; } cout << " The sum of the digits you have entered is = " << sum << endl; if ( ( sum % 2 ) == 0 ) cout << " " << sum << " is divisible by 2 " << endl; else cout << " " << sum << " is not divisible by 2 " << endl; // note here no need of return anything return 0;// because the return type of ' main ' is ' void ' } // end of main
VladV1V
Can anyone help with this? #include <stdio.h> #include <stdlib.h> int main() { int sz = 1; scanf("%d",&sz); int arr[sz],i; for (i=0; i < sz ; i++) { arr[i] = rand() % 100; printf("%d:%d\n",i + 1,arr[i]); } return 0; } Write return functions a pointer to an element with an arbitrary index-dimensional array of 10 elements I am quite new to C please sry if my code looks bad
Anonymous
Hi friends
Anonymous
Can we take the main function as void???
The signature for main in C is int main(void) or int main(int argc, char* argv[]) You can also use char** argv instead of char* argv[]
H4
#include <stdio.h> #include <string.h> int main() { freopen("oout.txt", "w",stdout); freopen("iin.txt", "r",stdin); int a[100],b,c,i,j,n,x,k,y,z=-10000; scanf("%d",&n); for(k=0;k<n;k++) { for(i=1;i<=3;i++) scanf("%d",&a[i]); // for(i=1;i<=3;i++) // printf("%d",a[i]); x=(a[1]+a[3])-(2*a[2]); // x=(a[1]+a[3]+1)-(2*(a[2]-1)); // printf("%d",x); // printf("%d",(a[1]+a[3])-(2*a[2])); if(x==0) { printf("%d\n",x); } else { if(x<0){ while(1){ // for(j=0;j<=1;j++) // { a[3]+=1; a[2]-=1; y=(a[1]+a[3])-(2*a[2]); // printf("%d\n",y); if(y>0){ y=((a[1]+a[3])-1)-(2*(a[2]+1)); printf("%d\n",y); break; } } // } } else{ while(1){ a[3]-=1; a[2]+=1; y=(a[1]+a[3])-(2*a[2]); // printf("%d\n",y); if(y<0){ y=((a[1]+a[3])+1)-(2*(a[2]-1)); printf("%d\n",y); break; } } } } } return 0; } why time limit excidded in todays div 2 contest
H4
in codeforce