VS - C99 or C11 Upgrade? + Programming Challenge

AceInfinity

Emeritus, Contributor
Joined
Feb 21, 2012
Posts
1,728
Location
Canada
I think Visual Studio needs to upgrade their support for the newer C specifications. As far as I know it only provides support for C89... So when I went to write a little code in C for a programming challenge...

Note: For those of you interested in trying this problem on your own, ignore the following code below and attempt this first on your own: https://icpcarchive.ecs.baylor.edu/external/62/6242.pdf

Code:
#include <stdio.h>
#include <stdlib.h>

int clean_scanf(long* n, long* k, long* q)
{
	int result = scanf("%ld %ld %ld", n, k, q);
	int ch; while ((ch = getc(stdin)) != EOF && ch != '\n');
	return result;
}


int F(int n, int k, int q)
{
	int ans;
	int* nums;
	int i, j = 0;

	if (n >= 0 && n < k) return 1;
	
	nums = (int*)malloc(k * sizeof(int));

	for (i = k - 1; i >= 0; i--) nums[i] = 1;
	for (i = 0; i < n; i++)
	{
		int sum = 0;
		int x; for (x = 0; x < k; x++) sum += nums[x];
		nums[j] = sum;
		j = (j + 1) % k;
	}

	ans = nums[j];
	free(nums);

	return ans % q;
}

int main()
{
	int caseNum = 0;
	long n, k, q;

	clean_scanf(&n, &k, &q);
	while (n + k + q != 0)
	{
		int result = F(n, k, q);
		printf("Case #%d: %ld\n", ++caseNum, result);
		clean_scanf(&n, &k, &q);
	}

	printf("\n...");
	getchar();
	return 0;
}

I had to adopt those changes, and It caused quite a bit of grief..

nRrGQnS.png
 

Attachments

  • fib_extended challenge.png
    fib_extended challenge.png
    35.5 KB · Views: 1
Last edited:
Doesn't MS use it's own specification for C++, that adopts some features of newer versions but not all? I didn't realise until this thread they didn't support the C99 standard, a bit surprising - any idea why they've gone for their own version rather than supporting the full specification?
 
I believe VS 2012 supports C++11. I thought I'd read that someplace. The initial advantages of VS 2012 though seemed to revolve around lots of C++ improvements however. With C though, it seems to be no better than C89... Even in VS 2012.
 
I think it partially supports it - there is a list of implemented features somewhere, but I don't think it fully supports everything in the C98 or C11 standards.
 

Has Sysnative Forums helped you? Please consider donating to help us support the site!

Back
Top