So I want to loop through a file line by line. Everytime there is a ':' in a line, put the string before it into label. (i know that right now label keeps getting reset without ever doing anything with it)
Code:
int search(FILE *inp) {
char line[80];
char label[11];
char *tokenPtr;
char delim1 = ':';
int lineNum = 1;
int i = 0;
while(fgets(line, sizeof line, inp) != NULL) { //loop through each line
for(i = 0; i < 11; i++)
label[i] = '\0';
if (line[0] != '#' && line[0] != ' ') { //if line doesnt start with # or a space...
tokenPtr = strtok(line, delim1); //split at :
//HOW DO I TAKE EVERYTHING BEFORE THE : AND ASSIGN IT TO label?
//label = stdrup(tokenPtr);
printf("%s\n", label);
}
}
else if(line[0] == '\n') {
continue; //dont increase line number
}
lineNum++;
}
return 0;
}