1. Why do lots of programmers use BUFSIZ as a size for their large arrays?? how big is it anyway??
2. Check this FAQ entry Option 3 , the example where the author uses a char array BUFSIZ big and a strtol() function.
when the user inputs a number in that char array , how will numbers fit in it??? like if he enters the number '42' , how will it be stored in that CHAR array???
3. i've saw someone doing this before :
im not used to point to a string without allocating space for it first and pointing to that space , how does the previous example work???
p = "hello world";
appreciate your help..
1) BUFSIZ is a standard macro that's the size of the buffer used by setbuf. It's generally a good large size for an input buffer. :) But we don't know the size, that's not specified.
2) Wow, I really confused myself.[/edit]
When reading from the stream, everything is a character. When the user types 42, it's actually the characters '4' and '2', not the number 42. That conversion is only made after the characters are extracted from the stream. So 42 fits in a char array simply because no conversions were performed.
3) The implementation handles memory for string literals, all you have to do is use them or save their address with a pointer provided you agree not to try and modify their contents.
1) BUFSIZ is set to 256 in <stdio.h> http://www-ccs.ucsd.edu/c/stdio.html#BUFSIZ
2) the character will be stored in arrayname[number] number is in your case 42
3) *p="hello world"; is the same as saying p[ ] = "hello world"; it allocates space to the size of the string specifically plus one extra for the '\0' . You could later use p as p,p,p, etc ...
1. No BUFSIZ is not set to 256 in stdio. It changes for each system. for me it is 8192.
2. It will not be put in array[numeryouenter] if I enter 82 it will be like this
It won't be in buffer;
3. You can access it with p, but you cannot edit the values or else you will get a segfault. This is just a pointer and that is read only memory(ROM)
>1) BUFSIZ is set to 256 in <stdio.h>
That's the lower limit. It's allowed to be more.
>2) the character will be stored in arrayname[number] number is in your case 42
>3) *p="hello world"; is the same as saying p[ ] = "hello world";
No, no it's not. :) The former points a pointer to a string literal, the latter initializes an array with "hello world" and sets the size accordingly.
gotcha by a second prelude:D
Thanks a bunch Prelude , linuxdude and qodsec :)