Thread: Similar thread: More token counting

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    178

    Similar thread: More token counting

    I am counting tokens in a tokenized string. I am not sure if it is MinGW or if I need a better compiler but no matter what I try, it crashes and has been crashing unless I am very careful to nurse and ginger it along compiling and running my program.

    Essentially I am doing the following:

    tokens is a pointer to tokens obtained through strtok on a string.

    I know I can pull the tokens out using *(tokens++). I can pull each token out character by character using that. however, when I try to do this in either of 2 ways -

    Code:
    while (tokens != NULL)
    {
           printf("%c", *(tokens));
    CRASH!

    How about -

    Code:
    switch (*(tokens))
    {
           case '  ':
           count++;
           break;
    
          ...
    
    }
    CRASH!!

    I have tried various ways to count the tokens in "tokens" and all have resulted in the exe crashing.

    Any help is appreciated.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    178

    Talking

    never mind, I am doing the token counting as follows:

    Code:
    while (tokens != NULL)	// Count number of tokens
    {
    	//printf("%s ", tokens);	// Could print them too right here
    	count++;
    	tokens = strtok(NULL, delmtrs);  // Nullifies previous token, pointing to next
    }
    I would still like to know why valid code that compiles and debugs fine, apart from pointer issues doing things they ought not to, causes crashes in C using MinGW.

    I code in Java and have to work to make the program crash and even then it soft resets at times. Still love C though cause I can hack memory easily and write viruses for all your computers easily

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by Imanuel View Post
    I would still like to know why valid code that compiles and debugs fine, apart from pointer issues doing things they ought not to, causes crashes in C using MinGW.

    I code in Java and have to work to make the program crash and even then it soft resets at times. Still love C though cause I can hack memory easily and write viruses for all your computers easily
    The problem isn't the compiler - it's the fact that it's being used by a complete idiot...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    >I can hack memory easily and write viruses for all your computers easily
    With your knowledge of C?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 02-26-2009, 11:48 PM
  2. Terminating secondary thread from another thread
    By wssoh85 in forum C++ Programming
    Replies: 13
    Last Post: 12-19-2008, 05:14 AM
  3. Thread Prog in C language (seg fault)
    By kumars in forum C Programming
    Replies: 22
    Last Post: 10-09-2008, 01:17 PM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. Replies: 12
    Last Post: 05-17-2003, 05:58 AM