program freezing

This is a discussion on program freezing within the C Programming forums, part of the General Programming Boards category; I've been trying to implement the strcmp method, but the following code causes my program to freeze - most specifically, ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    100

    Question program freezing

    I've been trying to implement the strcmp method, but the following code causes my program to freeze - most specifically, i've narrow it down to the line in bold.
    Code:
    for(ii = 0; ii < stackSize; ii++) {
            fgets(aa[ii], LINE_SZ, stdin);
    
            if(strcmp(aa[ii][0], "<") != 0) {
                printf("Bad input.\n");
                ii--;
            }         
    }
    How do I properly implement strcmp? I'm trying to see if the first character of each input line is "<" or not.

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    If it's the first character, it's not a string is it? Either use strncmp() or:

    Code:
    if(aa[ii][0] == '<')
    {
    Last edited by zacs7; 09-10-2007 at 05:32 PM.

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    100
    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

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