1

basically I am taking user input and using it to delete from a list, when this error has just been thrown. The code was working literally an hour ago so I don't know why Visual studio is now chucking a fit about it.

char courseName[100];
scanf("%s", courseName);
deletefromlist(&list, &courseName);

deletefrom list function takes (Courselist * self, char * data) as arguments.

How can i correct this error and in future avoid it? cheers!

Mohit Jain
  • 30,259
  • 8
  • 73
  • 100
Jonno Williams
  • 107
  • 1
  • 1
  • 8
  • Possible duplicate of [C - 'char \*\*' differs in levels of indirection from 'char (\*)\[6\]'](http://stackoverflow.com/questions/7524070/c-char-differs-in-levels-of-indirection-from-char-6) – Ilja Everilä Apr 12 '16 at 07:31

1 Answers1

5

Second argument of function accepts char *, so you should pass courseName instead of &courseName.

Or depending on the nature of deletefromlist, you may want to change the argument type.

Mohit Jain
  • 30,259
  • 8
  • 73
  • 100
  • yea I tried that one, the code still breaks. Ill have to have a look at my delete function more perhaps. But why isn't char * not the same as char(*)? since theyre both pointing to something – Jonno Williams Apr 12 '16 at 07:36
  • You declared `courseName` as an array of `char`, so `courseName` behaves (almost) like a `char *` pointer (it points to the first `char` of the array). In your delete function, make sure you have the correct safeguards to avoid overflow when you treat the array. – Quentin Apr 12 '16 at 07:47
  • ah yea, that makes sense since im getting memory access violations. cheers mate – Jonno Williams Apr 12 '16 at 07:51
  • Array when passed as argument to a function, depletes to the pointer to first element in array. – Mohit Jain Apr 12 '16 at 08:42