Hey all. I'm having a bit of problem with structs. Say we have a struct comprised of
some strings and ints.One of the strings is a keycode,which is used for hashing.So my program reads from a file some information,creates a struct and using that keycode it places the struct on a specific position on a struct array (so far everything ok).
Now,the second functionality should be,given a specific keycode,which may or may not exist in one of the arrays of the struct,if there is a struct with that keycode the struct containing it must be deleted.
So,question is,how do i set a struct to null?
Using printf i see that indeed the program works and finds the keycodes if they exist.
So,to put it simple,how do i set myArray[index] to null?
What i tried is declare a new myStruct,named cat2,then use the appendEntry(struct myStruct ca,int index) method.The appendEntry method copies
every field of "cat2" to myArray[index]. (i also tried myArray[index]=cat2; but same result.).Shouldn't every string field of cat2 be "" by default???
I print myArray using :
void printAll (void) {
for (int i=0;i<1000;i++) {
if (myArray[i].info[0]!='\0') {
printf("\n%s-%d-%d-%s-%s\n", myArray[i].name,myArray[i].number1,myArray[i].num2,myArray[i].lName,myArray[i].info);
}
}
}
So the problem is if i don't use the delete feature it prints eg
abcd-20-25-qwer-poi
and after using the delete feature (supposing i give "abcd" as key)
-20-25-qwer-poi
when it shouldn't be printed at all. I didn't post any code because its kind of messy,and because i'm guessing this is a noob mistake of mine,as a matter of handling structs.
Thanks in advance for your time!