I have been using Coderbyte.com the last couple of days for some coding challenges in C. I normally use Codeblocks as my IDE, I have noticed that sometimes the working solution in the Coderbyte IDE will throw an error in Codeblocks. For example:
#include <stdio.h>
#include <string.h>
void AlphabetSoup(char str[]) {
int i, j, length;
length = strlen(str);
char new_string[length];
char temp;
strcpy(new_string, str);
for (i = 0; i < length; i++) {
for (j = i + 1; j < length; j++) {
if (new_string[i] > new_string[j]) {
temp = new_string[i];
new_string[i] = new_string[j];
new_string[j] = temp;
}
}
}
// code goes here
printf("%s", new_string);
}
int main(void) {
AlphabetSoup(gets(stdin));
return 0;
}
In Codeblocks it is throwing at error in the main
function saying:
warning: passing argument 1 of 'gets' from incompatible pointer type [enabled by default]
anyways I don't understand why this solution is working on one IDE and not the other. Another time some code I put in said that it would only work in C99.
Now when I run this code in Codeblocks it crashes, but not on Coderbyte.
My questions are:
1) Are there different versions of C?
2) Is this code still correct, or would it be better to use char *
for the function parameter
I'm still new to C