Reading string

char string[30];
gets(string);  
char *tok;
tok = strtok(string," ");
while (tok != NULL)
{
printf("\nvalue: %s",tok);
tok = strtok(NULL," ");
}

If you enter this:
This is some text and number 100

you will get:

This
is
some
text
and
number
100

So far so good. The user can enter max 15 words ( not signs ).
This are my variables:

ascii  wordOne[10]= "user";
ascii  wordTwo[10]= "ID";
...
//if(strcmp(wordOne,string ) == 0)

Now, how can i compare if the first word that im getting from input is equal to my var wordOne, or if the second word is equal to wordTwo and so one ? And then again, how can i check if the input line contains number ?.
I dont know how is this working in openAT but in C i would write some program that would read a sign and then compare it with each sign in the variable. This would not be good idea so if someone can post some example how to do this, that would be great.

well you are using c in all functions except when you are using the adlapi functions, i do not know if you can use gets. (who is the standard input? modem has a keyboard?)

i think that you need to get data at first , from uart, sms gprs or other adl flow, then you can use the data as in C, the string functions are avaible

"The user can enter max 15 words "

well just store the strings in arrays and then compare every one with wordone and wordtwo wm_strcmp is avaible

to know if there is a number in the string you can compare every char in the string using isdigit, just like in C

Keyboard and sms. For now im testing with sms ( example showes gets, but this is for future).

This

and

are the part that i dont know how to make.

I mean, i know i could make something like:

ascii message[SIZE], char ;
u8 count;
ascii string[30];
gets(string); 
ascii *tok;
tok = strtok(string," ");
while (tok != NULL)
{
TRACE(("\nvalue: %s",tok));
tok = strtok(NULL," ");
}
while ((char = getchar()) != "\n")
{
 message[count++] = char;
...

but i dont think that this would work in openAT.

To put this simple :unamused: i dont know how to make this in openAT and if you have any code for support, please post it, becuse im bit lost in this.

the C functions are the same in openAT, from this point you can programming exactly like you do in C, adl is an API for control de modem but you can write your own C functions and call them from your program

if you do not have a good C knownledge i recommend to you get it first.

void tokenArr(char *theString,char *charArr[10],char *chDel);
void showArray(char *charArr[10]);

int main()
{
   char *varC[10];
   char String[30];
   char *token ;
      
  gets(String);
  tokenArr(String,varC," ");
  showArray(varC);
  return 0;
}

void tokenArr(char *theString,char *charArr[10],char *charDel)
{
    	char *token;
    	int i = 0;
    	
    	token = strtok(theString," ");      //first token
    	charArr[i] = token;                   // save in array
    	i++;
    
    	while (token != NULL){
    		token = strtok(NULL, charDel);
    		charArr[i] = token;
    		i++;
    	}
}
void showArray(char *charArr[10])
{
        for (int i =0;i < 10;i++)
        {
         //if (strcmp(charArr[i],"This") == 0)
         printf("\nvalue: %s",charArr[i]);
        }
        
}

This code will give me:

This
is
some
text
and
number
100

and data stored in array, but i dont know how to compare the strings.
Btw. do i need to make char to int conversion if i want to read/check if the input is number or is there some other way ?.

Again, this is plain, vanilla, standard textbook ‘C’ - nothing specifically to do with Wavecom nor Open-AT.

Look-up the use of the standard string-compare functions in your ‘C’ textbook - strcmp() and strncmp().

// if( strcmp( charArr[i], "This" ) == 0 )

If you uncomment that line, the compiler should give you a warning; think about the warning - it tells you what’s wrong with the call…

The first thing that you must know it is that when you create a project with the wizard that wavecom gives you have the main that means your main function is unuseless (it defined too 2 vars for stack). you can move your main code there.

generate the project and then you can your code to the main function supplied in appli.c

About your code it has some things that show that you have not to much control about C, let me explain to you that C it is easy to make some simple things but it is difficult to manage in a proper way, i strongly recomend that you take some tutorials or books about C.

void tokenArr(char *theString,char *charArr,char *chDel);
void showArray(char *charArr);

you are passing the address of the first position in the array, it has no sense give the length of the array (indeed you have no way to know that if you do not pass an extra argument giving the size)

i think you can not use use in wavecom software

i hope you are trying to declare a array of 10 pointers to char and not a pointer to an array of 10 chars.

and why do not initialize to NULL ??? as you must know the auto vars have garbage as init values

another thing, you have 10 pointers to char, but do you get the arrays space? where are declared?
(as i see in your code the pointers will point to somewhere in String (all of them) )

i strongly recomend init vars
char String[30] = “\0”;
char *token = NULL;

i think you will be agree that is better as you give the token in the function

token = strtok(theString, charDel); //first token

this not save the string in the array, indeed you have no array of chars you have only an array of pointers to char,

you are assign the pointer of charArr[i] to point to token (some memory location inside of String array)

to save it on array you must reserve some mem position by define an array and then use strcpy if you really want to do that.

do you know that this will be assign to your last used charArr[i] = NULL?
that means that you can only get 9 words before to crash
do you considerer to make some secure array length test?

well guy ansi C and gcc used by wavecom do not allow you to declare i inside the for loop you have to do previusly.

int i = 0;
for (i =0;i < 10;i++)

since we have not standard output like a monitor in the modem i think that you can not use printf inside wavecom modem .

do you still think that you do not need a tutorial of C?

Hi awneil and ofernandez and thank you for your explanation !

Im doing this part in borland becuse it compiles much faster and i thought to made some small changes and past it to openAT.
It look’s like that this is maybe bad idea… :unamused:

@ofernandez
I have send you PM. Please take a look and tell me what you think.

Again, thank you for your explanation…