Миршохид
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'
olli
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
Spirit
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
Naina
#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
Is the create function working properly ? I think in create function u should copy the address of head to a temporary variable and then use that temporary variable to create the link list . As changing the head each time would also change its address.
Adarsh
ARx
#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
Why head->next points to head?
Adarsh
ARx
#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
in count you use (p->next != head) as a condition, but p never changes
Adarsh
Adarsh
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 👋
NagaRaju
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
Pavel
Anonymous
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
Anonymous
slm
how can draw a curve of a function ?
Mustapha
#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
Is this C or C++
Adarsh
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
moyo
Igor🇺🇦
Igor🇺🇦
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;
itsmanjeet
Anton
Anonymous
Anonymous
And have the function with def vars
itsmanjeet
Anonymous
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
'''''''
Anonymous
'''''''
Anton
Anton
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.
Anton