Anything wrong with this declaration?

This is a discussion on Anything wrong with this declaration? within the C Programming forums, part of the General Programming Boards category; There doesnt seem to be anything wrong with it, but for some reason my program is crashing when it gets ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    4

    Anything wrong with this declaration?

    There doesnt seem to be anything wrong with it, but for some reason my program is crashing when it gets to the following statement.

    This is the declaration:
    Code:
    typedef		struct word{
    	char name[25];
    	int count;
    	struct word *next;
    	}	WRD;

    and this is the line in my code it doesn't like:
    Code:
    if (tempName[j] != p->name[j])

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >if (tempName[j] != p->name[j])
    Is p declared like this?

    WRD *p;

    If so, do you also assign memory to it?

    p = &someWord;

    or

    p = malloc(sizeof *p);

    At the time of the crash, is j out of bounds? Less than 0 or greater than 24?

    Just a hint for future debugging, most often when you crash at runtime, the bug is earlier in the code than the line where you actually die.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >if (tempName[j] != p->name[j])

    if (strcmp(tempName[j], p->name[j]) != 0)

    I don't know why it's crashing though.

  4. #4
    Registered User
    Join Date
    Jul 2003
    Posts
    85
    Originally posted by swoopy
    >if (tempName[j] != p->name[j])

    if (strcmp(tempName[j], p->name[j]) != 0)

    I don't know why it's crashing though.
    should it stay if (tempName[j] != p->name[j]) ?

    he's just comparing two characters

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >should it stay if (tempName[j] != p->name[j]) ?

    >he's just comparing two characters

    Yes, you're right Scappy. Scratch that. I guess I wasn't thinking.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to compile projects ?
    By manzoor in forum C++ Programming
    Replies: 31
    Last Post: 10-15-2008, 12:52 PM
  2. forward declaration
    By C_ntua in forum C++ Programming
    Replies: 14
    Last Post: 09-29-2008, 12:29 PM
  3. Replies: 6
    Last Post: 08-23-2008, 02:16 PM
  4. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 11:17 AM
  5. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21