Question in Char Array

Thread Starter

brian25

Joined May 13, 2013
37
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
 

magnet18

Joined Dec 22, 2010
1,227
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
 

shteii01

Joined Feb 19, 2010
4,644
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.
 

WBahn

Joined Mar 31, 2012
30,071
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
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.
 

Thread Starter

brian25

Joined May 13, 2013
37
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..
 

WBahn

Joined Mar 31, 2012
30,071
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.
 

Thread Starter

brian25

Joined May 13, 2013
37
i used arduino lib

Regexp.h

Rich (BB code):
MatchState ms;
  char * str = smsbuffer;
  ms.Target (str);
  
  unsigned int index = 0;
  char buf [100];
  
  while (true)
  {
  char result = ms.Match ("(%a+)" "(%-?%d+)", index);
  
   if (result == REGEXP_MATCHED){
     for (int j = 0; j < ms.level; j++);
     gsm.WritePhoneNumber(result[j],(%-?%d+);
     index = ms.MatchStart + ms.MatchLength;
   }
   else 
     break;
  }
}
can you help how to correct this one.. tnx
 

WBahn

Joined Mar 31, 2012
30,071
can you help how to correct this one.. tnx
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!
 

shteii01

Joined Feb 19, 2010
4,644
Arduino forums is better place to ask these questions. They would be familiar with the libraries, functions and their use.
 

Ian Rogers

Joined Dec 12, 2012
1,136
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?
 
Top