This block of code will compile, but gives me a runtime error:
before the first comment is a header that is included in the file that you may need to analyze my code.
typedef char *string;
typedef struct
{
string fieldName;
string value;
}oneField;
/* this starts the function*/
link tokenize (string input_string)
{
int numOfSpaces;
string next, temp;
oneField thisRecord;
/* used for head of linked list */
link head;
int field, counter = 0;
void insert(link*, oneField);
head = 0;
while(1)
{
numOfSpaces = 0;
next = next_word(input_string, &numOfSpaces);
/* next = the word which we will work with here */
if(counter == 0){
strcpy(thisRecord.fieldName, next);
}
if(counter == 1){
strcpy(thisRecord.value, next);
}
/* if the word returned by next_word was the last word
in the input string, then the element at that length
should be the null character, in which case we will
break from the loop */
counter++;
if(input_string[strlen(next)] == '\0')
break;
input_string += strlen(next) + numOfSpaces;
}
return head;
}
If I comment out the strcpy methods, it will run fine, but for some reason it will not copy the value of the string into the struct. Any help would be greatly appreciated.
Reguards,
Tyler S. Breton