Find space inside Array?

This is a discussion on Find space inside Array? within the C Programming forums, part of the General Programming Boards category; Hello, I'm trying to find the second space inside a array, here's my code: Code: Space=0; PL=12; //came from another ...

  1. #1
    Registered User
    Join Date
    Jun 2007
    Location
    Rio de Janeiro, Brasil
    Posts
    48

    Find space inside Array?

    Hello, I'm trying to find the second space inside a array, here's my code:

    Code:
    Space=0;
    PL=12; //came from another function that is working right!
    PB=0; 
    			   // find PartB from start of numbers until 2nd space
    			   while (Space!=2)
                   {
                        PartB[PB]=NewStr[PL];
    					if (PartB[PB]==" "){
    						Space++;
    					}
    					PB++;
    					PL++;
                   }
    			   PartB[PB]='\0'; //close string
    seams that any space is found then reach the end of the array then abort.

    but HAVE more than 2 spaces in the string!

    thanks!

  2. #2
    life is a nightmare
    Join Date
    Apr 2007
    Posts
    127
    if (PartB[PB]==" ")
    that's not right
    if (PartB[PB]==' ')
    i think it should be like that

  3. #3
    Registered User
    Join Date
    Jun 2007
    Location
    Rio de Janeiro, Brasil
    Posts
    48
    thanks m8! worked great!

  4. #4
    life is a nightmare
    Join Date
    Apr 2007
    Posts
    127
    i am just wanna tell you why did it work
    in my code i am looking for the integer value that equals to space in the ascii table
    not for the hall string " " that's cannot be done because you are trying to compare a constant string with a char type
    [Warning] comparison between pointer and integer
    if is there any thing wrong in my replay i hope you will fix it for me
    i am just trying to be helpful because i am really love this site

  5. #5
    Registered User
    Join Date
    Jun 2007
    Location
    Rio de Janeiro, Brasil
    Posts
    48
    thanks for your explanation! now I understand! :P

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 60
    Last Post: 01-09-2009, 12:09 PM
  2. Array inside an 2dimensional array
    By aserf in forum C Programming
    Replies: 18
    Last Post: 03-22-2008, 06:28 PM
  3. Find String inside Array?
    By hajas in forum C Programming
    Replies: 8
    Last Post: 06-20-2007, 01:48 PM
  4. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 08:51 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM

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