0

I am running C in eclipse using MinGW, and run into problems when I try and call strtok(), despite the fact that the program runs on my professor's computer just fine. Did i not install/setup MinGW correctly (i thought none of my programs would run if this were the case, however)?

As I said, the code runs fine on another computer, so I'd assume that the code itself is not at fault, but my computer/setup.

I am pretty new to setting up my own environment, so any help is greatly appreciated!

EDIT:When I run the program, it simply fails (program.exe has stopped working). When I run the debugger, it gets to the line:

    char *token = strtok(string, ",");

And a window pops up saying: No source available for "strtok() at 0x752bce40"

Building the code provides no error messages or warnings.

EDIT2: The whole code for up until this line is:

char *val1 = "5,7,3,4,";
char *val2 = "5,7,4,";
node *n = NULL;

insert(&n, toSet(val1));

where toSet is:

set toSet(char *string)
{
    set out = (set)malloc(n*sizeof(int));
    int result, place;
    result = place = 0;
    char *token = strtok(string, ",");
    --more code--

FINAL EDIT: Changing *val1 to val1[] worked, thanks! But why would it then run on my professor's computer?

  • 4
    What kind of problems, exactly? What error message(s) are you getting? Are you getting errors when you try to build the code or when you try to run it? – John Bode May 23 '14 at 19:38
  • 1
    How is `string` declared, and what is the last thing assigned to it? Also, the message from the debugger is telling you that it's trying to show you where `strtok` is failing, but the debugger doesn't know where the source code for it is and therefore cannot show it to you. – indiv May 23 '14 at 19:49
  • @indiv is most likely correct. If string is declared as, say, char * then the storage can easily be in read only memory (at least it can under Linux). strtok writes to string (which is why it's grouped with "gets" as functions-not-to-use). If string is uninitialised, or NULL, or points to readonly memory then the program will fault. – carveone May 23 '14 at 19:53
  • 1
    You can not change the string literal. `char *val1 = "5,7,3,4,";` change to `char val1[] = "5,7,3,4,";` – BLUEPIXY May 23 '14 at 20:01
  • The "No source available" message is not relevant to the problem; that's just the debugger complaining that it doesn't have access to the source code for the standard library. If it runs on your professor's computer, it's probably because you weren't running exactly the same program. (It's possible, but unlikely, that your professor's system doesn't complain about modifying string literals.) – Keith Thompson May 23 '14 at 20:17

0 Answers0