Initialize A 2D Array With User Input | C Programming Example

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

so awesome. im buying your udemy class now hope to see more portfolio buildi projects

IMdrummerTab
Автор

Hello I have a question. Let's say I have an array[2][2] and the scanf() will read row inputs in a single line. For row 0, I type 1 2 3, and row 1 I type 4 5, I will end up with an array of {{1, 2}, {3, 4}}. What I want is {{1, 2}, {4, 5}}, so '3' should be discarded as each row should only have 2 elements, is there a way to deal with this? Thanks

KendrewLok
Автор

I’m still learning how to use c, so I’m sorry if the question is weird.
I don’t get how the compiler is knowing the number of rows and cols in your example!
Thnx for the video, it was perfect.

احمدفايز-هي
Автор

Hi sir...firstly sorry for my rusty and bad English...your video is easy to understand, I had an assignment and that required me to fill up the football match table such as game played, game won, draw and so on...because im new in c language, can you explain how to done this...i dont have any i idea what to do..just give some idea to start. This some part of the question : NONE OF THE COLUMNS OF WIN, DRAW AND LOSE CAN HAVE VALUES MORE THAN 3 AS THE NUMBER OF GAMES PLAYED IS 3(MAXIMUM)...i realy need some guidance to done this. TQ in advance Sir

hazlibinhayatstudent
Автор

Thanks ! it is very helpful, but in this video the columns and rows have already been declared/decided which is 3 rows & 5 cols, what if the users want to input rows and cols with how many they want it to be?( without deleting existing ones)

daffaadirapratama
Автор

Thank you for a very informative tutorial video. I have been searching information about writing a 2D array to a FILE and printing it from a FILE. Do you think it is possible to do so even my 2D array is not full of elements. The reason is that I am making a study schedule with 2D array[date][time] of struct., and ofc there might be sometimes for a break so that [index][index] spot would be blank .

If it is possible, do you have any advice to print the whol time table ?

Besr regards

juliusphung
Автор

Hi! Thanks for the video, it was really helpful. How could it be done if I need to initialize an array one by one? For example, I have a menu and one option says "Add a student", and if that option is selected, the it needs to fill "Name" and "Age", which both of these will be in the first element of the array, once it´s done, it will go back to the menu, asking again to enter an option. Also, hope you're having a good day/night!

karenvaldez
Автор

great video, could you explain a way to do this but give the user the option to choose the number of rows columns? for instance, i am doing an assignment where there is a sort of terrain 'grid' made for finding treasures etc, but the user needs to choose the size of terrain (for example, user input 6 8 would generate a terrain grid with 6 rows and 8 columns)

rafacastellano
Автор

Very good video, but what do if we also wanna make row and cols with user input ? Can you please explain it to me ?

kizki
Автор

whatever anything I do or did or know or did not knew or I do anything now or anything

ryanalnaser
Автор

Thanks, it helped me a lot. I want to do the exact same thing, but instead of using numbers, I'm using characters (not strings, just letters). The thing is that it gets stucked in the nested for, but when I introduce the letters manually, they're printed with no problems. Hope you can help me and tnxs again.
#include<stdio.h>
#include<string.h>
int main ()
{
int i, j;
char letters[2][3];
//char letters[2][3] = {{'a', 'b', 'c'}, {'d', 'e', 'f'}};

for(i=0;i<=1;i++)
{
for(j=0;j<=2;j++)
{
printf("\nIntroduzca la letra %d, %d: ", i, j);
scanf("%s", &letters[i][j]);
}
}

for(i=0;i<=1;i++)
{
for(j=0;j<=2;j++)
{
printf("%c\t", letters[i][j]);
}
printf("\n");
}
return 0;
}

luisjasso