硬件的重点是它应该从文件中读取:
int func(int arg) { int x = 7; char c = 'a'; arg = x + c; return arg; }
并输出:
func, arg, x, c
//or optionally also the next line
int, char, return
所以我的问题是在我的输出中获取应该出现的字符的问号,并且 strcmp 没有为我的 if 语句返回零,这需要它工作(注意:我有很多评论和 printf 来帮助我弄清楚我哪里出错了):
while((d=fgetc(function_file)) != EOF) {
//start by checking for any defines and just looping until a new line character comes up
if( d == '#')
flag = true;
if((d == '\n') && (flag)){
//flag which says if I am searching for a newline but only after a define/include
//was found will I say the flag is not needed anymore to allow normal parsing
flag = false;
} //end of check for a define function
if( (flag == false) && (d != '#') ) {
//this is where the main chunk of code goes to do all the parsing
if((d != ' ') && (d != '\t') && (d !='\n') && (d != '{') && (d != '}') && (d != '(') && (d != ')') && (d != '*') && (d != '=') && (d != '+')) {
printf("Character read is : %c\n", d);
start = true;
temp[count] = c;
count++;
}
}//end of main chunk of code
if((start == true) && ((d == ' ') || (d == '(') || (d == ')') || (d == '{') || (d == '}'))) {
//end a string and compare it hear
if(match == false) {
temp[count] = '\0';
printf("String: %s\n", temp);//*********************************DEBUGGING***********
start = false;
int compare;
for(compare = 0; compare < key_counter; compare++) {
int optimus;
optimus = strcmp(keywords[compare], temp); //************** ONE OF THE ERRORS IS HERE***************************************?
if(optimus == 0){
//printf("this is actually runnning");//*********************************DEBUGGING***********
int len = strlen(temp);
bizarro_keywords[bizarro_key_counter] = (char *)malloc(sizeof(char) * (len +1));
memcpy(bizarro_keywords[bizarro_key_counter], temp, len +1);
printf("\nWhats inside bizarro_key_counter right after it is allocated memory: %s", bizarro_keywords[bizarro_key_counter]);
bizarro_key_counter++;
match = true;
}
}
int x;
for(x = 0; x < count; x++)
temp[x] = '\0';
count = 0;
} else { //if match equals true just grab the next available string
//printf("is this one ever running?");
temp[count] = '\0';
start = false;
printf("String: %s\n", temp);
int len = strlen(temp);
identifiers[iden_counter] = (char *)malloc(sizeof(char) * (len +1));
memcpy(identifiers[iden_counter], temp, len +1);
iden_counter++;
match = false;
int x;
for(x = 0; x < count; x++)
temp[x] = '\0';
count = 0;
}
}
}//end of while loop for reading the whole file
这是我的输出:
Character read is : i
Character read is : n
Character read is : t
String: ???
Character read is : f
Character read is : u
Character read is : n
Character read is : c
String: ????
Character read is : i
Character read is : n
Character read is : t
String: ???
Character read is : a
Character read is : r
Character read is : g
String: ???
Character read is : i
Character read is : n
Character read is : t
String: ???
Character read is : x
String: ?
Character read is : 7
Character read is : ;
String: ??
Character read is : c
Character read is : h
Character read is : a
Character read is : r
String: ????
Character read is : c
String: ?
Character read is : '
Character read is : a
Character read is : '
Character read is : ;
String: ????
Character read is : a
Character read is : r
Character read is : g
String: ???
Character read is : x
String: ?
Character read is : c
Character read is : ;
String: ??
Character read is : r
Character read is : e
Character read is : t
Character read is : u
Character read is : r
Character read is : n
String: ??????
Character read is : a
Character read is : r
Character read is : g
Character read is : ;
String: ????
我是 C 的新手,我不知道为什么我会得到那个输出。请提示。