Anonymous
Your logic for deletion is wrong. Assume there are only 2 nodes in your list and both of them have the value 4. Now go through your code for this use case and you will figure out what is wrong.
As for the Segmentation fault, now assume there is only one node in your list with value 4 and go through your logic again. You will find out why it will crash at the while loop.
Kirk
Thank you! i see now
Ольга
Good day. As advised, I solved the problem with gets (), but still can not find an example on the Internet how to compare the elements of the structure and data from the user. I will be glad for any help https://onlinegdb.com/iYSv_SNbY
Ольга
How can I pass a dynamic array to a function? I still can not achieve the right option. I will be grateful for the hint
Vlad
Or something like that
Vlad
Is it C or C++?
Ольга
C, but I have 2d matrix
Ольга
It is same like you say?
Vlad
Is it dynamically allocated?
Vlad
If so you'd have to pass two sizes
Vlad
And float**
Vlad
But it won't work for arrays on stack
Vlad
For arrays on stack you'd have to create a pointer array for it to be compatible
Ольга
But it won't work for arrays on stack
I'm sorry, but like it is stack? How it's look
Vlad
Array with automatic lifetime duration
Ольга
Type it will be in the stack even if the size of the array is set by the user. Yes?
Vlad
In C there's also VLA which does what you've described with the same syntax
Vlad
Those are also on stack.
Vlad
But allocated through alloca
Vlad
Anyway. The point is that their type decays into T*
Vlad
Not T**
Vlad
If your matrix has a flat buffer(i.e T*). Then you'd have to address it as arr[i * width + j]
Vlad
So you pass T* and two sizes into the function
Ольга
Oh Okey I try
Boom
hey, please I have doubt about c program
Boom
is there anyone to help me
Boom
#include <stdio.h> void main() { int age[100][10] = {0}; int person; char name[28][10] = {0}, email[28] = {0}; printf("Enter the number of travellers\n"); scanf("%d", &person); for (int i = 0; i < person; i++) { printf("Enter the name of person %d\n", (i + 1)); scanf("%s", &name[i]); printf("Enter the age of person %d \n", (i + 1)); scanf("%d", &age[i]); } for (int j = 0; j < person; j++) { printf(" the name of person %d is %s \n", (j + 1), name[j]); printf(" the age of person %d is %d \n", (j + 1), age[j]); } }
Vlad
please tell me what i'm doing wrong
What do you need two dimensional arrays for?
Ehsan
it should be: int age[10];
Boom
What do you need two dimensional arrays for?
because I'm taking the input of several person and i have to print it number wise
Ehsan
What do you need two dimensional arrays for?
I think he confused char* and primitive data types
Boom
it should be: int age[10];
cant i take two dimensional array in int?
Vlad
And then make an array of structs
Ehsan
int age[10]; // 10 people ages
Boom
Okay. What you need to do is to declare a struct
but can you tell me why it is not working?
Ehsan
but can you tell me why it is not working?
you are using multi-dimensional array wrong
Boom
im sorry, im so dumb
Ehsan
no worries
Vlad
but can you tell me why it is not working?
You fucked up sizes. [10] ought to be first size
Vlad
For the strings
Ehsan
char[28][10] this is different than other data types, char is a primitive data type that stores a character. If you make a string (which what names are essentially) you need multiple characters; that's why you make it two dimensional.
Boom
You fucked up sizes. [10] ought to be first size
but i want 10 rows and in each row i want 100 characters to be filled
Ehsan
also it should be char[10][28]
Ehsan
which means (10 names with maximum of 28 character for each name)
Vlad
In C arrays are row margin
Boom
thank you all for being so supportive
Boom
char[10][100]
so it means 10 rows and 100 columns , right?
Boom
thank you so much
Ehsan
np
Ольга
So you pass T* and two sizes into the function
Sorry. So I know I'm an idiot. But I can't figure out what's wrong again https://onlinegdb.com/JhqPPRxfm
Ehsan
Sorry. So I know I'm an idiot. But I can't figure out what's wrong again https://onlinegdb.com/JhqPPRxfm
main.c:22:17: error: ‘sum’ undeclared (first use in this function); did you mean ‘suma’? 22 | if (sum[i] < sum[j]){ | ^~~ | suma
Vlad
First things first. What does the function suma supposed to do?
Vlad
2) You return from it but never assign the value
Vlad
3) You cast pointer to a function as a int**
Vlad
Btw you can't return a pointer to the local array
Vlad
Array dies right after the function exit
Ольга
First things first. What does the function suma supposed to do?
If make like Int **g[i] =sum[i] it be better?
Ольга
I tried to fix it, but I'm not sure that anything has gotten better https://onlinegdb.com/aXNM3xhUx
Vlad
Sum of columns?
Ольга
Sum of columns?
Yes, the sum of each column of the matrix
Vlad
then you'd have to return int*
Vlad
int* sums = malloc(cols * sizeof *sums);