isalpha || ispunct

This is a discussion on isalpha || ispunct within the C Programming forums, part of the General Programming Boards category; I am writing a program to see if the next character that isn't a \n \t or ' ' is ...

  1. #1
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926

    isalpha || ispunct

    I am writing a program to see if the next character that isn't a \n \t or ' ' is a punctuation or a letter. I have this function but i get a seg fault. Does isalpha or ispunct mess with memory somehow or something??
    Code:
    int search_for_word(char *string,int offset){
            offset=0; /*just for this example*/
            while((!isalpha(string[offset])) || ((!ispunct(string[offset])))){
                    offset++;
            }
            printf("X == %d\n",offset);
            if((isalpha(string[offset]))){
                 return 1;
            }
            else{
            return 0;
    }
            return 1;
    }

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >Does isalpha or ispunct mess with memory somehow or something??
    It certainly does if you let it.

    > while((!isalpha(string[offset])) || ((!ispunct(string[offset])))){

    Use &&:
    while((!isalpha(string[offset])) && ((!ispunct(string[offset])))){

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    isalpha and ispunct do not mess with the actual memory themselves. The information is passed by as an integer so it just a value. Use and instead of or like swoopy said but you might want to include a way to see if you hit the null character so if you do you can stop and avoid going outside of your array

  4. #4
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    Oh I did that was just an example I wrote real quickly. It is in my real code. the seg fault stopped when I changed || to &&

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 01:13 AM
  2. process killer on a loop
    By Anddos in forum Windows Programming
    Replies: 8
    Last Post: 01-11-2006, 01:50 AM
  3. Replies: 4
    Last Post: 11-23-2003, 07:15 AM
  4. Massive Function Problem
    By Marc Sharp in forum C Programming
    Replies: 10
    Last Post: 11-19-2003, 08:49 PM
  5. Tic Tac Toe Help
    By aresashura in forum C++ Programming
    Replies: 1
    Last Post: 11-21-2001, 12:52 PM

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