Variable size array, user size input added. #1170

Fixed Issue #1170
Variable size array, user size input added.
This commit is contained in:
Pushkar Sharma 2015-10-04 10:34:31 +05:30
parent 9b46fe7e57
commit c7e552c448

View File

@ -130,7 +130,9 @@ int main(void) {
// can be declared as well. The size of such an array need not be a compile // can be declared as well. The size of such an array need not be a compile
// time constant: // time constant:
printf("Enter the array size: "); // ask the user for an array size printf("Enter the array size: "); // ask the user for an array size
char buf[0x100]; int size;
scanf("%d", &size);
char buf[size];
fgets(buf, sizeof buf, stdin); fgets(buf, sizeof buf, stdin);
// strtoul parses a string to an unsigned integer // strtoul parses a string to an unsigned integer