Question in Char Array

Discussion in 'Programmer's Corner' started by brian25, Oct 9, 2013.

  1. brian25

    Thread Starter Member

    May 13, 2013
    37
    0
    i'm using gsm lib and i want to separate the content of smsbuffer. ex Hello World then i will disregard the Hello and i will only get the World and store in Another byte/char array. tnx
     
  2. magnet18

    Senior Member

    Dec 22, 2010
    1,232
    124
    you have 2 posts on here, neither of them are well worded or clear, I'm not even sure what your question is in this one

    If you would like help, please clearly explain what you're trying to accomplish, what your problem is, and what you've tried to fix it

    It makes it a lot easier for those interested in helping you
     
  3. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,387
    497
    You can move contents of cells in Array A to cells in Array B.

    Example.
    char ArrayA[]={'1','a','2','c','5','p'};
    char ArrayB[]={'b','b','b','b','b','b'};

    ArrayB[0]=ArrayA[1];
    ArrayB[1]=ArrayA[3];
    ArrayB[2]=ArrayA[5];




    So. When we started ArrayB has 6 cells, the index for cells start with zero. When we finished, we moved some characters from ArrayA to ArrayB. The new ArrayB now holds:
    ArrayB[0]=ArrayA[1]=a
    ArrayB[1]=ArrayA[3]=c
    ArrayB[2]=ArrayA[5]=p
    ArrayB[3]=b
    and so on.
    So new ArrayB is now {'a','c','p','b','b','b'}.

    Normally moving contents of array cells is done using a loop so you use fewer lines of code.
     
  4. WBahn

    Moderator

    Mar 31, 2012
    17,743
    4,795
    It's completely unclear what you are really trying to get at.

    What is smsbuffer? It is a specific buffer in some hardware device? It is simply the name of a static array? Is it a pointer to dynamically allocated memory? What?

    Are you saying that you want to copy just the right N characters from one array into another? Are you saying that you want to coppy all but the left N characters from one array into another?

    Are you asking if there is a specific function in the gsm lib that will do what you want (whatever that turns out to be)?

    Are you really talking about a character array, or about a string? There's a difference.
     
  5. Ian Rogers

    Member

    Dec 12, 2012
    158
    29
  6. brian25

    Thread Starter Member

    May 13, 2013
    37
    0
    my plan is how to separate this text coming from sms buffer Add 0000011111 then get those numbers and store it in char phone number.
    WritePhoneNumber(byte position, char *phone_number)

    i'm using strtok but have no success. i need to store atleast 10 numbers in SIM Card..

    tnx to you reply. hope you can help with this..
     
  7. WBahn

    Moderator

    Mar 31, 2012
    17,743
    4,795
    What is "this text".

    What are "those numbers"? 0000011111?

    Is WritePhoneNumber() the function you are trying to write?

    What is the "position" argument?

    How does WritePhoneNumber access the sms buffer, since it's not passes as an argument? Is it a global?

    Remember. We only know what YOU tell us.

    You need to be much, much more exact in describing what you need to have happen.

    Given concrete examples. Describe your data structures completely.
     
  8. Ian Rogers

    Member

    Dec 12, 2012
    158
    29
    Show me the complete sentence coming in from the GSM unit... What needs separating and what needs storing...
     
  9. brian25

    Thread Starter Member

    May 13, 2013
    37
    0
    i used arduino lib

    Regexp.h

    Code ( (Unknown Language)):
    1. MatchState ms;
    2.   char * str = smsbuffer;
    3.   ms.Target (str);
    4.  
    5.   unsigned int index = 0;
    6.   char buf [100];
    7.  
    8.   while (true)
    9.   {
    10.   char result = ms.Match ("(%a+)" "(%-?%d+)", index);
    11.  
    12.    if (result == REGEXP_MATCHED){
    13.      for (int j = 0; j < ms.level; j++);
    14.      gsm.WritePhoneNumber(result[j],(%-?%d+);
    15.      index = ms.MatchStart + ms.MatchLength;
    16.    }
    17.    else
    18.      break;
    19.   }
    20. }
    can you help how to correct this one.. tnx
     
  10. WBahn

    Moderator

    Mar 31, 2012
    17,743
    4,795
    No. Not without a crystal ball, since you still won't tell use what it needs to do in order to be considered "correct".

    The code you've posted is also syntactically incorrect on multiple instances. Just count the number of open and close curly braces. Then count the number of open and close parentheses. Then look at the strings that appear to not be delimited with quotes. How can we help debug the logic of code that isn't even legally constructed?

    How are we supposed to know what the ms and gsm classes do? We know that ms in an instantiation of the MatchState class, whatever the hell that is. But we don't even know the class name of whatever class gsm in an instantiation of.

    You declare a variable named buf that is a 100 element array of chars, yet don't use it. Is that an oversight? How are we supposed to know since we don't know what you are trying to do?

    What is REGEXP_MATCHED ? You use it as though it is a #define constant, but you then use result as a pointer to an array. Again, mind reader... not.

    Then you have a for() loop that does nothing except burn up some CPU cycles since it is an empty loop and the control statements accomplish nothing except setting j equal to the value of ms.level. And notice that you use the variable j after the loop has finished but the variable j was only declared to be in scope within the loop!
     
  11. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,387
    497
    Arduino forums is better place to ask these questions. They would be familiar with the libraries, functions and their use.
     
  12. WBahn

    Moderator

    Mar 31, 2012
    17,743
    4,795
    A very good suggestion.

    Though the posted code has problems that go way beyond what libraries he's using.
     
  13. Ian Rogers

    Member

    Dec 12, 2012
    158
    29
    As WBahn quite correctly states.... We have no knowledge of this "Matchstate" class..

    If you are using an inbuilt Arduino lib, there's not much we can do here..

    Do you have a completed example smsbuffer before parsing?
     
Loading...