how would this be done

int main(void)
{
	char string[]="231 number 73 word 1 2";
	char *ele;
	ele=strtok(string," ");
	while (ele != NULL)
	{
		if (*ele == '0' || *ele == '1' || *ele == '2' || *ele == '3' || *ele == '4' || *ele == '5' || 
					*ele == '6' || *ele == '7' || *ele == '8' || *ele == '9')	
			TTS(ele);
		else	
			printf("%s\n", ele);
			ele=strtok(NULL," ");	
	}
	return 0;	
}

I'm trying to separate the words from the numbers. So when tokenizing it encounters a number I can pass it to an array.
the TTS function is what should be able to do it
]

void TTS(char *punt)
{
	printf("%s\n",punt); 
	int i=0;
	char num[20];  //where I wanna store the number
		
	for (i=0;i<20;i++)
	{
		*punt=num[i];
		punt++;
		printf("%c",num[i]);
	}
	
	for (i=0;i<20;i++)
	              printf("%c",num[i]);  //checking if anything is stored
	
}

Output is:
231
which corresponds to the first printf in TTS, which I added to make sure that at least it prints the number as a string.

I'm newb, have trouble with pointers and arrays. I'm sure there's an easy way around this. Any help?

In words, what is this TTS function supposed to do?

#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(int argc, char**argv)
{
   const char delim[] = " ";
   char text[] = "231 number 73 word 1 2";
   char *token = strtok(text, delim);
   while ( token )
   {
      if ( isdigit(*token) )
      {
         puts(token);
      }
      token = strtok(NULL, delim);
   }

   return 0;
}

/* my output
231
73
1
2
*/

From your two threads, this is my best guess with what you might be asking.

Hey thanks for helping out.
The thing is this is a text to speech engine which I'm developing along with Asterisk (telephony PBX).
The caller inputs his ticket number, the database processes the ticket number and returns the string like "Your ticket number 123 is solved".
I have to be able to separate the words and numbers, because each word has a sound file linked to it.
For example, using the StreamFile function from Asterisk,
StreamFile(your);
outputs the sound file your.gsm and the caller hears the recorded file.
But for the numbers, there's already a function that takes the whole number as an array and processes it, then outputing different sound files.
For example, for 123 it would output
StreamFile(One)
StreamFile(hundred)
StreamFile(twenty)
StreamFile(Three).
so the caller hears one hundred twenty three.

Thats why I have to take the numbers from the string that is tokenized and store them in arrays.
Since functions can't take arrays as arguments, I'm thinking passing the pointer to it that strtok saves as the word or number in this case, and then inside the TTS function make the pointer go over the word, saving each character to an array. In the end, I would want to have an array, in this example, of this kind
number[1][2][3]

It all boils down to the numbers being in an array, coming from the tokenized phrase which are saved with pointers, right?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.