Миршохид
Hi friends, i just wonder, should i use #define macros with variadic parameters, or its better to stick with templates... i want to customize code to be compatible simultaneously with few platforms/frameworks... for example Arduino/MBED/CMSIS for STM32
Amu
has anyone ever here ever done kernel programming?
Ludovic 'Archivist'
Amu
#meta Yes
Please let me know if you’re familiar with weensyOs, I need to isolate process address space in my next assignment and i’m a bit confused
Anonymous
Can anyone tell me best resources for learning STL
Mr
/get stop_teaching_c_as_cpp_preamble
Adarsh
#include<stdio.h> #include<stdlib.h> struct node { int data; struct node *next; }*head=NULL; void create(int a[],int size) { struct node *t,*last; int i=0; head=(struct node *)malloc(sizeof(struct node)); head->data=a[i]; head->next=head; last=head; for(int i=1;i<size;i++) { t=(struct node *)malloc(sizeof(struct node)); t->data=a[i]; t->next=last->next; last->next=t; last=t; } } int count(struct node *p) { int count=0; do { count++; } while (p->next!=head); return count; } void Delete(int index) { struct node *p,*q; if(index<1||index>count(head))return; if(index==1) { p=head; while(p->next!=head)p=p->next; if(p==head) { free (head); head=NULL; } else { p->next=head->next; free (p); head=p->next; } } else { p=head; for(int i=0;i<index-2;i++) { p=p->next; } q=p->next; p->next=q->next; free (q); } } void Dispay(struct node *p) { do { printf("%d ",p->data); p=p->next; }while(p!=head); } int main() { int a[]={1,2,3,4,5,6}; create(a,6); Delete(1); Dispay(head); return 0; } plsss help idk what is wrong with my delete function
Adarsh
Why head->next points to head?
Its circular linked list
Adarsh
in count you use (p->next != head) as a condition, but p never changes
yes i got that mistake and made changes now it is working fine
NagaRaju
I'm trying to create a dynamic array and reinitialising when elements are more than the array size. I have taken an array which contains two elements. When memory is allocated for blockChoice [variable] then every blockChoice variable can store two elements. blockChoice[0][0] = array[0]; blockChoice[0][1] = array[1]; I'm using clang linux compiler when I try to compile the code $./a $ Segmentation fault This is my code ----------------------------- #include <stdio.h> #include <stdlib.h> int **blockChoice; int used = 0; void initArray (int size) { blockChoice = malloc (sizeof(int) * size); if (blockChoice == NULL) perror ("malloc"); for (int i = 0; i < 2; i++) { blockChoice[used][i] = (int)malloc (sizeof(int)); } } void insertElement (int *array) { blockChoice[used][0] = array[0]; blockChoice[used][1] = array[1]; used++; } void reInitArray (int size) { blockChoice = realloc (blockChoice, size); } int main () { int array[2] = {9,10}; int size; printf ("\n Enter the size of the array : "); scanf ("%d",&size); while (size <= 5) { initArray (size); insertElement (array); size++; reInitArray (size); } // printing printf ("\n\n"); for (int i = 0; i < used; i++) { for (int j = 0; j < 2; j++) { printf ("Array[%p] = %d", blockChoice[i], blockChoice[i][j]); } printf ("\n"); } return 0; } I'm stuck please help me!!
Denis
/a
Jacky
all is fault exactly
Jacky
why u use the malloc function already, and then and the store local array of integer for it?
Norn Sothea
Hi everyone 👋
Anonymous
I have an object which has a pointer to an mmap buffer. When I'm trying to copy memory from the mmap buffer to a buffer outside the object, I get a segfault. If I try to copy data to a buffer in the same object, it copies it successfully.
Anonymous
How does it even make sense?
Anonymous
the whole program is singlethreaded
Anonymous
I do "char* gBuffer = new char[1024];" outside the object Then I run "obj.GetData(gBuffer, 1024);" inside GetData I do: *gBuffer = *mmapBuff; and it segfaults
Anonymous
But if I create a new char array inside GetData, it works perfectly
Hasan
int main() { double a; double x1; double x2; printf("bir sayi girin\n"); scanf_s("%f", &a); x1 = a; x2 = x1 - ((x1 * x1 - a) / (2 * x1)); while (1) { if (x2-x1 > 0.0001 || x1-x2>0.0001) { x1= x2; x2 = x1 - (((x1 * x1) - a) / (2 * x1)); printf("hh %f", x2); } else { printf("%f", x2); break; } }
Hasan
What is the problem
Hasan
Can you help me
Dima
read the rules
klimi
What is the problem
you tell us c:
Anonymous
slm how can draw a curve of a function ?
Anonymous
Is this C or C++
You can easily tell because he is using C libraries if it was C++ <stdio.h> would be replaced with <cstdio>
moyo
Good Evening Guys, my name is Moyo please there a learning you guys have undergone here. Because I kind of feel lost in conversation that's here. I'm also a C++ programmer. Thanks.
Spirit
i have a class that has a member that is a pointer to a struct returned from a c function is there a way to use unique_ptr with this? so that the class will automatically free up resources when out of scope?
Spirit
specifically my class is calling MYSQL * conn = mysql_init(NULL) in it's constructor. from what i gather with mysql you call mysql_close(conn) and then delete conn
Igor🇺🇦
i have a class that has a member that is a pointer to a struct returned from a c function is there a way to use unique_ptr with this? so that the class will automatically free up resources when out of scope?
If your pointer was returned from C function it wasn't created with new operator. Meaning you cannot use delete, meaning you cannot use unique_ptr with it.
Talula
This is a group for C++ not math but answer is no... O(n^2) = O(n*n)
Apk
they are equivalent
Pavel
n*(n+n) is equal to n*2*n, which is 2*(n^2) and with big-O notation you drop the constant, so O(2*(n^2)) becomes O(n^2)
Shayan
Hello
Shayan
Create a function that checks the Array overflow condition before insertion(C++)
Norn Sothea
Hello everyone
Pavel
Stop spamming please, write in one message
Pavel
I see there's a function in the standard library for that https://en.cppreference.com/w/cpp/numeric/lcm by the way, next time try to google before asking, it was literally the first result in google
YUSUF
Any one know about ffmpeg..
Vignesh
Hello all, can any one answer this? Write a addition function in c++ which works for all tge datatypes. Take care of overflow condition
Vignesh
Please *
Anonymous
for(i=0;i<size-1;i++) { if(i<position) { temp[i]=a[i]; } if(i>=position) { temp[i]=a[i+1]; } }
Anonymous
Guys i could not understand this part of the code
Anonymous
Can somebody please help me?
Yapp
Can somebody please help me?
You are applying a for loop and going through an array If the value of I is less than the value of position then you're giving the temp array the same value as array a Else You're giving temp array the value which is one position forward in array a.
itsmanjeet
Hey all, do we have any deep learning library or a simple library for sequential model (rnn)
Anton
Hi everyone! C related question. How do you set default values for variables in struct? Is it possible to do at the moment of structure defenition? typedef struct s_store { char *content; ssize_t length; ssize_t tmp; size_t nl; } t_store;
Anonymous
And have the function with def vars
Anton
And have the function with def vars
That will work actually. Thank you :)
itsmanjeet
Hi everyone! C related question. How do you set default values for variables in struct? Is it possible to do at the moment of structure defenition? typedef struct s_store { char *content; ssize_t length; ssize_t tmp; size_t nl; } t_store;
struct store { char *content; ssize_t length; ssize_t tmp; size_t nl; } store_default = { "default value", 0, 0, 0}; struct store val = store_default; You can do something like this for default
Anonymous
specifically my class is calling MYSQL * conn = mysql_init(NULL) in it's constructor. from what i gather with mysql you call mysql_close(conn) and then delete conn
You just need to create a wrapper around MySQL_close which accepts a conn* pointer and pass that in as one of the template arguments to unique_ptr.
Anonymous
If you are using C++14, you can just compute the GCD. Then computing LCM is straightforward. LCM(a,b) = a*b/GCD(a,b)
Anonymous
Hello all, can any one answer this? Write a addition function in c++ which works for all tge datatypes. Take care of overflow condition
Write a template function and then handle overflows using numeric traits for the template parameter T
Anonymous
we can also assign default values by using calloc instead of malloc while allocating memory right?
calloc zeroes out memory. So if you want default values to be anything other than zero, it won't work out.
Anonymous
It tells me that val takes only constant values.
The solution given should work. Are you trying to create the struct variable in global scope?
Anton
Does it count as global?
Anonymous
I think yes. It is located in the header file.
include <stdio.h> struct store { char *content; ssize_t length; ssize_t tmp; size_t nl; } store_default = { "default value", 0, 0, 0}; int main() { struct store val = store_default; } This would work fine.