A tutorial on the basics of using 2D arrays in C. Source code: github.com/por.... Check out www.portfolioc... to build a portfolio that will impress employers!
Hey Mate, You are the best! Love and respect to You, dear professor, from a regular ukrainian C fan. I wish I could be Your student at the university 😌
actually this is my field of work "Matrix", I work with finite elements analysis and I will implemented it this week in one of my Home Work. Thank you for your help
Do you mean copy the elements of one int array into another into array? That would look something like this: int a[] = {1,2,3,4,5}; int b[] = {0,0,0,0,0}; for (int i = 0; i < 5; i++) b[i] = a[i]; ^^ this would copy the elements of 'a' into 'b'. If this isn't what you mean let me know, I can try to help. :-)
I have a question, if I have a 2d array how can I make it so that the first line and first row are all filled with the number 0? (basically I want any 'coordenate' with x or y = 0 to have the numeric value 0). This is the code I have for generating the matrix: #include #include #include #define MAX_LIMIT 1000 int main (){ int l, c; int i, j; int m, n; char str[MAX_LIMIT]; int sum; int zero = 0; scanf(" %d %d", &l, &c); // scan number of lines and columns fflush(stdin); int **mat = (int **)malloc((l+1) * sizeof(int*)); if (**mat == NULL) return; for(i = 0; i < l+1; i++) mat[i] = (int *)malloc((c+1) * sizeof(int)); for(i=1; i
I’m not sure what you mean by “first line” and whether that is different from the “first row”. But a loop that takes a counter variable from 0 to the number of columns could be used to set the first row elements all to 0. :-)
love the vids , was wondering can you make a video about an array of lists, (an array and each block of the array points at a list , and how to move through it ) thanks
Hopefully one day I can do a video like that Hassan! :-) I do have a Udemy course on Linked Lists, but I know this is something different in terms of a data structure.
@@PortfolioCourses im in uni and just finished my exams i dont think im going to use C anymore so wondering if u have java course for next semester that i can follow .thanks
Do you want to store individual characters into a 2D array? Or do you want to store strings into a 2D array of chars, with one string stored per row of the 2D char array? I'm just asking because there is a difference between how we do each of those things. :-) This video shows how to read a file into an array of strings: ua-cam.com/video/X-1qodkHCHo/v-deo.html. Reading from user input would be similar but instead of a file we would read user input using a technique such as one of these: ua-cam.com/video/f8589Y9LHHg/v-deo.html. Maybe I can make videos on both of these topics, they are good ideas Yogesh. :-)
Hey Mate, You are the best! Love and respect to You, dear professor, from a regular ukrainian C fan. I wish I could be Your student at the university 😌
actually this is my field of work "Matrix", I work with finite elements analysis and I will implemented it this week in one of my Home Work. Thank you for your help
That's awesome! And you're welcome! :-)
thank you so much for your tutorials
You're very welcome! :-)
Please how can I replace an int array with a different int array?
Do you mean copy the elements of one int array into another into array? That would look something like this:
int a[] = {1,2,3,4,5};
int b[] = {0,0,0,0,0};
for (int i = 0; i < 5; i++)
b[i] = a[i];
^^ this would copy the elements of 'a' into 'b'. If this isn't what you mean let me know, I can try to help. :-)
@@PortfolioCourses thanks
You are awesome buddy!!
Thank you! :-)
I have a question, if I have a 2d array how can I make it so that the first line and first row are all filled with the number 0? (basically I want any 'coordenate' with x or y = 0 to have the numeric value 0). This is the code I have for generating the matrix:
#include
#include
#include
#define MAX_LIMIT 1000
int main (){
int l, c;
int i, j;
int m, n;
char str[MAX_LIMIT];
int sum;
int zero = 0;
scanf(" %d %d", &l, &c); // scan number of lines and columns
fflush(stdin);
int **mat = (int **)malloc((l+1) * sizeof(int*));
if (**mat == NULL)
return;
for(i = 0; i < l+1; i++) mat[i] = (int *)malloc((c+1) * sizeof(int));
for(i=1; i
I’m not sure what you mean by “first line” and whether that is different from the “first row”. But a loop that takes a counter variable from 0 to the number of columns could be used to set the first row elements all to 0. :-)
Nice - thank you.
You’re welcome Firas! :-)
love the vids , was wondering can you make a video about an array of lists, (an array and each block of the array points at a list , and how to move through it ) thanks
Hopefully one day I can do a video like that Hassan! :-) I do have a Udemy course on Linked Lists, but I know this is something different in terms of a data structure.
@@PortfolioCourses im in uni and just finished my exams i dont think im going to use C anymore so wondering if u have java course for next semester that i can follow .thanks
@@hasan-hr5kl One day I do want to have a Java course, but I'm not sure if it will be in time for next semester for you.
@@PortfolioCourses thanks anyways.
How to take input in 2d char array in c ?
Do you want to store individual characters into a 2D array? Or do you want to store strings into a 2D array of chars, with one string stored per row of the 2D char array? I'm just asking because there is a difference between how we do each of those things. :-)
This video shows how to read a file into an array of strings: ua-cam.com/video/X-1qodkHCHo/v-deo.html. Reading from user input would be similar but instead of a file we would read user input using a technique such as one of these: ua-cam.com/video/f8589Y9LHHg/v-deo.html.
Maybe I can make videos on both of these topics, they are good ideas Yogesh. :-)
@@PortfolioCourses thanks for the response ya i was asking about storing strings in 2D array .
OK, I may be able to do a video on that actually. In the meantime, hopefully those links can give you some ideas. :-)
Amazing, please do that with a function 🙏
What would you like to see done with a function and 2D arrays exactly? :-) I'm just curious, maybe I can make a video on it.
@@PortfolioCourses just to see how a function can be used to display 2d array 🙏
Please how can I contact you so as to get advice and helps on c programming. I really appreciate your videos ❤️
@@ettajunior5087 OK I'll try to make a video on that, and maybe one on passing 2D arrays to functions.
@@ettajunior5087 I'm not able to do 1 on 1 tutoring at the moment due to time constraints, but I try to answer questions posted on these videos. 🙂
great video tanks
You're welcome Juan! :-D