From c7e552c448c5a562a3ff5f442a7ed834aec04d9e Mon Sep 17 00:00:00 2001 From: Pushkar Sharma Date: Sun, 4 Oct 2015 10:34:31 +0530 Subject: Variable size array, user size input added. #1170 Fixed Issue #1170 Variable size array, user size input added. --- c.html.markdown | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'c.html.markdown') diff --git a/c.html.markdown b/c.html.markdown index 8e631de4..36621a9e 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -130,7 +130,9 @@ int main(void) { // can be declared as well. The size of such an array need not be a compile // time constant: 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); // strtoul parses a string to an unsigned integer -- cgit v1.2.3 From 2e987df42225e6bdf824584058467aaffc73fb49 Mon Sep 17 00:00:00 2001 From: Pushkar Sharma Date: Mon, 5 Oct 2015 00:52:47 +0530 Subject: replaced scanf with fscanf. --- c.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'c.html.markdown') diff --git a/c.html.markdown b/c.html.markdown index 36621a9e..db2ac930 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -131,7 +131,7 @@ int main(void) { // time constant: printf("Enter the array size: "); // ask the user for an array size int size; - scanf("%d", &size); + fscanf(stdin, "%d", &size); char buf[size]; fgets(buf, sizeof buf, stdin); -- cgit v1.2.3