I have a piece of code that loops through a char array string to try and detect words. It loops through and if the detects A - Z or a - z or an _ (underscore) it will add it to a char array. What I need, because they're words, is to be able to put them into a string which I can then use another function to check and then can be discarded. This is my function:
char wholeProgramStr2[20000];
char wordToCheck[100] ="";
IdentiferFinder(char *tmp){
//find the identifiers
int count = 0;
int i;
for (i = 0; i < strlen(tmp); ++i){
Ascii = toascii(tmp[i]);
if ((Ascii >= 65 && Ascii <= 90) || (Ascii >= 97 && Ascii <= 122) || (Ascii == 95))
{
wordToCheck[i] = tmp[i];
count++;
printf("%c",wordToCheck[i]);
}
else {
if (count != 0){
printf("\n");
}
count = 0;
}
}
printf("\n");
}
At the moment I can see all of the words because it prints them out on separate lines.
the content of WholeProgram2 is whatever all the lines are of the file. and it is the *tmp argument.
Thank you.
isalpha()
and'-'
. – unwind Nov 12 '14 at 14:31wordToCheck
array already (but remove the=""
initializer, global variables arezero initialized
thus you will get a NUL terminated string in the array, given thattmp
is not too long.) It's a global variable, you can access it from other functions. Please clarify what you want or what the problem is. – Jite Nov 12 '14 at 14:34Ascii = toascii(tmp[i]);
? Where is theAscii
defined? What's its type? – EOF Nov 12 '14 at 14:35wholeProgramStr2
. usually, spaces, tabs etc. are used as delimiters for this type of parsing. Is this what you are doing? – ryyker Nov 12 '14 at 14:42