Facebook – https://www.facebook.com/TheNewBoston-464114846956315/
GitHub – https://github.com/buckyroberts
Google+ – https://plus.google.com/+BuckyRoberts
LinkedIn – https://www.linkedin.com/in/buckyroberts
reddit – https://www.reddit.com/r/thenewboston/
Support – https://www.patreon.com/thenewboston
thenewboston – https://thenewboston.com/
Twitter – https://twitter.com/bucky_roberts
Amazon Auto Links: No products found.
again you need to use uint, you are throwing away half the usable space by using int instead of uint
Bucky, you forgot the ‘free’.. there is a memory leak.
I want to post some codes on your forum but I don’t know how to do it! how can I submit a post on your forum? I registered to be a member but I don’t find the link to post on your website! I have a question regarding:
conditional_expression?expression1:expression2
Buckey you are awsome
i am struggling to watch the video number 48 and 49…it is not being played or it takes infinite time to buffer…while other videos are running properly. Please +Bucky Roberts
Why couldn’t you ask the user how many numbers he wants to enter-int a, scan this a, and then create int tab[a].
this program does’nt work for me
Hey bucky your program is wrong because the exact average is 40.4 not 56…
my program is :
#include
#include
#include
#include
#include
free()
how can i make it printf(“你叫什么名字?”); ?
There’s a bug in the resulting average. It should be 40.4. The reason is the declared variables all need to be set to zero at the top. Like follows: int i, howMany = 0; int total = 0; float average = 0.0; int * pointsArray = 0;
How do I make a 2d array with indefinite size?
I want the user to input the number of rows and columns, and just then create the matrix.
Can someone help?
the average code doesn’t work….I found out that the error comes from initializing the variable “total” it should be “float” from the beginning…..cmiiw…
well, I know what is heap but from this example did not get the benefit of using it.
One thing I learned is that in C (c99) on a Linux box, an uninitialized int in the global (file) scope will default to 0. However, in function scope (i.e. in the main() function), it’s an indeterminate, or bizarre value. In my specific case, the value was 4195824, which was really throwing my total and average off :-D. Apparently, in Windows environments, an uninitialized int always defaults to 0. StackOverflow was quite useful in explaining this issue: http://stackoverflow.com/a/1597426
How come you don’t just declare total as a double instead of an int and type cast?
1 questions guys, can someone explain to me what is the use of ‘heap’part in the overall program? will wait for ur kind reply 🙂
hi check out this program please :
#include
#include
#include
#include
#include
Guys i don’t get why in some videos he uses “fGet/fImput” and in other videos he uses “printf/scanf”…?
Hey Bucky! You forgot to free the memory 😛
Now what is the difference between allocating memory via “whatever = (int *) malloc(howMany, sizeof(int) );” and “int whatever[howMany];” ? Is it more than the possibility to free the memory later?
Thanks a lot 🙂
I dont see the REAL USE of this crap Heap ,for example watch this BEST MATCHS programme i could have just done it with array :
int i,howmany ;
int array[] ;
printf(“how many numbers do you want to enter ? ” ) ;
scanf(“%d”, &howmany) ;
for(i=0;i
#include
#include “dev.h”
#include
#include
how do i use this for strings?
/*
feel free to comment on this code.
*/
#include
#include
int main()
{
int numSize, i;
int total = 0;
int * pIntArray;
float average = 0.0;
printf(“How many numbers do you want to calculate the average?n”);
scanf(” %d”, &numSize);
pIntArray = (int *) malloc(numSize * sizeof(int));
printf(“Enter them below…n”);
for (i=0; i < numSize; i++) { scanf(" %d", &pIntArray[i]); total += pIntArray[i]; } average = (float) total / (float) numSize; printf("Average is %.2fn", average); free(pIntArray); return 0; }
i still don’t get the advantage of using the heap. we can define the memory size by coding like that
int size;
printf(“how many number do you want to average:n”);
scanf(“%d”, &size);
int pointArray[size];
how it calculates me the average wrong?i mean if i enter 5 numbers lets say 4,4,4,4,4 it will calculate the average 17.200001
why is that? plz help!!
Enter them then:
23.2
55.4
2.65
65.4
5
9.23
The average of your 6 numbers is: 6564233273361341000000000000000.00
this is what i got after input 6 numbers.What have I done wrong? As I said in a previous comment i did copy/paste the code from the tutorial but modified (except variable i) from int to float.Also I did initialize all variables, set them equal to 0.I also entered free(pointsArray); after i print out the average and should probably mention I use Windows 10.Could it be a Windows 10 bug?
Mine didn’t work so I followed Daniel Jansen’s advice in the comments and set my total to 0. Now it works fine 🙂
???? it doesn’t work, when I type in two numbers, 50 and 100, it gives me 79.00000?
int main()
{
int i, howMany;
int total;
float average = 0.0;
int * pointsArray;
printf(“How many numbers would you like to average? n”);
scanf(” %d”, &howMany);
pointsArray = (int * ) malloc(howMany * sizeof(int));
printf(“Enter them boy! n”);
for(i = 0; i
Please help!
In the line
PointArray=(int*) malloc( howmany * sizeof(int))
I put 0 instead of howmany ( to get the meaning of heap) and i put 100. There is still the same answer. Why i get the answer when i put howmany =0?
As there is not enough memory for pointArray?
Question: Still Confuse with total+=pointsarray. how can all the numbers be store when the variable total is not set 0.0. i though you need to make that variable 0.0 so the total can store ever loop?
i tried to add five numbers 12+12+12+12+12 and the result is 110!
I’m not native english speaker and I’m wondering what does “tomato tomatoes” mean xd.
well i can store more than i declare that i can . for example if i allocate memory for four integers i can store five with no compiling error or something. why is that?
can anyone explain whats use of free(pointername);
why should we use &pointarray in scanf because we are declaring pointarray as a pointer
So what’s the difference between creating an array from malloc and pointers to just doing pointsArray[howMany] ?
It’s true. You will get the right average only if you set everything to 0 at the beginning. By the way, why isn’t there an “&” before average in the last printf? Shouldn’t be used one there, because it’s a float?
I started watching this video lessons on 1.5 video speed. And now, when I go back to normal, I understand how Bucky is speaking slowly. God damn dude, you are lazy.
Bucky I like your tutorials, however I find them hard to view when you use small fonts. It would be nice if you could make your fonts bigger in the program listings so people who have a visual handicap could see what your doing? Thanks…
Can you not do this without malloc but just declare int array[n] in stack after n has already acquired value from user input?
Thanks
howcome you dont need to declare your array at the start, all you have is a pointer?
i have a problem with my code, please can someone help me?
When I type number after the expression”” how many numbers do you want to put in?” and then I type the numbers, it always require me to type one more number. For example, i type 3 to say that I will type 3 numbers , but it ask me to type 4 numbers after the “put your numbers now” expression.
However, the output of total and average is correct, which is the total of first 3 numbers and the average of the first 3 numbers that I typed in.
here is my code.
#include
#include
#include
#include
#include
I have one question. Then I allocate a smaller amount memory say 3*sizeof(int), it still accepts 4 integers or more. What is explonation of that? Shouldn’t it crash because I enter more number that it can accept?
Buddy i don’t see where you done wrong but practically the average of the numbers you gave in run is 40.7% 😛
So the program has done a mistake 😛
Anyway cool videos you got here bro! 🙂 Impressed! (Y)
This works:
#include
#include
#include
#include
#include
I know this might be a stupid question but what is the difference between using your code and something like this:
int newArray[howMany];
int newTotal = 0;
float newAverage = 0.0;
for (i = 0; i < howMany; i++) { scanf("%d", &newArray[i]); newTotal += newArray[i]; } newAverage = (float)newTotal / howMany; printf("My way average is: %f", newAverage);
hey bucky , i think the average u hv got is wrong , it should be 40.4,,,
plzzz do reply
What is the difference between using malloc and not?
int howMany, i;
scanf(“%d”, &howMany);
int pointArray[howMany];
pointArray[0] = 4;
printf(“%d”, pointArray[0]);
Compared to
int howMany, i;
scanf(“%d”, &howMany);
int pointArray = malloc(howMany * sizeof(int));
pointArray[0] = 4;
printf(“%d”, pointArray[0]);
These both function exactly the same on my end. Why use malloc?