Thread: segmentation fault

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    27

    Unhappy segmentation fault

    Hello!

    I written a procedure that is supposed to only include one blank
    where there are more thatn one space.
    Example "A' ' ' 'D' ' 'E' 'FG' 'R' 'G' ' 'T"
    should be "A D E FG R G T"
    (' ' stands for space )
    It works in turbo c but not in linux
    I get segmentation fault all the time.
    What have i done wrong


    Here is the code
    Code:
    char *noDoublespace(char str[]){
    	int flag_isspace=0;
    	int i=0,y=0;
    	while(str[i]){
    		if(str[i]==' ' && !flag_isspace){
    			flag_isspace=1;
    			str[y]=str[i];
    			y++;
    		}
    		else if(str[i]!=' '){
    			flag_isspace=0;
    			str[y]=str[i];
    			y++;
    		}
    	i++;
    	}
    	str[y]='\0';
    }
    "Can i really learn this? If i cant, why bother?"

  2. #2
    Registered User
    Join Date
    Dec 2002
    Posts
    27
    I do it the second way.
    like this
    Code:
    noDoublespace(str);
    
    printf("%s\n",str);
    and have declared char *str="somethin...";
    "Can i really learn this? If i cant, why bother?"

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    27
    Ok, thanks for the help.
    Now i see the big picture.
    "Can i really learn this? If i cant, why bother?"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segmentation fault problem
    By odedbobi in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2008, 03:36 AM
  2. Segmentation fault
    By bennyandthejets in forum C++ Programming
    Replies: 7
    Last Post: 09-07-2005, 05:04 PM
  3. Segmentation fault
    By NoUse in forum C Programming
    Replies: 4
    Last Post: 03-26-2005, 03:29 PM
  4. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM
  5. Segmentation fault...
    By alvifarooq in forum C++ Programming
    Replies: 14
    Last Post: 09-26-2004, 12:53 PM