Im getting an error that is really frustrating me in my C program.
the error is:
main.c(65): error C2371: 'extractVals' : redefinition; different basic types
directClass is suppose to accept a reference to a char, specifically line 20 (in the switch case ‘g’) using variable s. Im not sure how they are not the same basic type, but im not very good with C, so im not great at identifying all issues. Any help would be great.
#include <gl\glew.h>
#include <gl\freeglut.h>
#include <gl\GLU.h>
#include <stdio.h>
void directFile(char input[100]){
char switchVal [10] , *s = switchVal;
float val1, val2, val3, val4;
s = strtok(input, " \n\0");
printf("Told str is %s\n", s);
switch(*s){
case '#':
printf("%s is a comment. Has no bearing on application\n", s);
break;
case 'g':
printf("%s is the command to translate an object!\n", s);
extractVals(s);
break;
case 's':
printf("%s is the command to scale, now which one is it?\n",s);
break;
case 'r':
printf("%s will rotate the image!\n",s);
break;
case 'c':
if(strcmp(s , "cone") == 0){
printf("It appears you have your self a %s\n", s);
} else if (strcmp(s , "cube") == 0){
printf("%s is cool too\n" , s);
} else if (*s == 'c'){
printf("Welp command was \"%s\", lets change some colors huh?\n",s);
}
break;
case 't':
break;
case 'o':
break;
case 'f':
break;
case 'm':
break;
}
}
void extractVals(char *input){
while(input != NULL){
printf("%s\n", input);
input = strtok(NULL, " ,");
}
}
void makeLower(char *input)
{
while (*input != '\0')
{
*input = tolower(*input);
input++;
}
}
int main(int argc, char *argv[]) {
FILE *file = fopen(argv[1], "r");
char linebyline [50], *lineStr = linebyline;
char test;
glutInit(&argc, argv);
while(!feof(file) && file != NULL){
fgets(lineStr , 50, file);
makeLower(lineStr);
printf("%s",lineStr);
directFile(lineStr);
}
fclose(file);
glutMainLoop();
}
Your error is because you did not provide a prototype before calling
extractVals(). When the compiler runs into such a case, it assumes that the function is declared like:Then later when it finds the definition, it conflicts with this assumption. This error can be fixed by adding an appropriate prototype, either before
directFile()or in a header that you include: