473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Divide words on syllables

hi everyone. i have to write a prog that divedes words on syllables for one language. the algoritm itself is ok.i take from user the string convert it to char string make the operation and put it to new string with difined size,but then the new string is displayed (and it is shorter than strings length) the empty spaces show squares. how can i solve this problem?
May 19 '07 #1
13 5208
JosAH
11,448 Expert 8TB
hi everyone. i have to write a prog that divedes words on syllables for one language. the algoritm itself is ok.i take from user the string convert it to char string make the operation and put it to new string with difined size,but then the new string is displayed (and it is shorter than strings length) the empty spaces show squares. how can i solve this problem?
A little tip: System.out.println() is your friend: stick in those debug print statements
everywhere where you expect something could be wrong, You'll most likely
hunt down that bug in one short session.

kind regards,

Jos
May 19 '07 #2
i am already using this function.
May 20 '07 #3
JosAH
11,448 Expert 8TB
i am already using this function.
We can't help you any further if you don't post some relevant snippets of code.
Today my crystal ball is in its charger so I can't make psychic guesses ;-)

kind regards,

Jos
May 20 '07 #4
here i am sending some code
May 21 '07 #5
String s = textfield2.getText();

String st=new String(s);

p=st.length();

len=p;

//from string to char
for (int c = 0; c < len; c++)
{
str[c] = st.charAt(c);
}
//write to str1 from back
for(int l=0; str[l]!='\0'; l++)
{
str1[len-1] = str[l];
len--;
}

//checking
for( k = 0 ; str1[k]!='\0'; )
{
if((str1[k]=='a')||(str1[k]=='o')||(str1[k]=='e')||(str1[k]=='u')||(str1[k]=='i'))
{
str2[j] = str1[k];
k++;
j++;
i++;
str2[j] = str1[k];
j++;
i++;
str2[j] = '-';
j++;
k++;
i++;
}//end of if
else
{
str2[j] = str1[k];
j++;
k++;

}//end of else
}//end of for
i=i+p;
int t=i;

char[] str3 = new char[??];

//converting
for(int m = 0; m < i; m++)
{
str3[t] = str2[m];
t--;

}

newstr = String.valueOf(str3);

g.drawString(newstr, 50, 130);

everything is ok but the empty cell in str3 (!because size is larger than the string itself going to be!)are also being copied to newstr and display square shapes. but when i put the exact size that str3 has to have it gives errors.what should i do?
May 21 '07 #6
JosAH
11,448 Expert 8TB
I've been trying to understand what your code does and I'm lost; you should
check the API for the String and StringBuffer class because a lot of stuff
you're trying to accomplish the hard way can be done using just a few simple
method calls using the API for those classes. e.g. reversing a String can be
done this way:
Expand|Select|Wrap|Line Numbers
  1. String reverse(String s) {
  2.    return new StringBuffer(s).reverse().toString();
  3. }
I don't understand where that '\0' character comes from. Are you trying to
translate some C code for this?

Also you don't need to copy Strings to other new Strings so often. Maybe you
want/can elaborate on *what* the rules are you want to use for finding the
syllables of a word?

kind regards,

Jos
May 21 '07 #7
actualy i use C PL but i have to write it in Java couse of that i have problems."\0" symbol i use to define the end of string.
May 21 '07 #8
JosAH
11,448 Expert 8TB
actualy i use C PL but i have to write it in Java couse of that i have problems."\0" symbol i use to define the end of string.
Strings in Java aren't terminated by '\0' characters. Instead of hacking your way
through, can you tell *what* the syllable rules are? Then we can simple start
from scratch.

kind regards,

Jos
May 21 '07 #9
ok, for this language rule is very simple, in one syllable there can be 1 vowel and one or two consonants.(mek-tep, o-kul, ki-tep)
May 22 '07 #10
JosAH
11,448 Expert 8TB
ok, for this language rule is very simple, in one syllable there can be 1 vowel and one or two consonants.(mek-tep, o-kul, ki-tep)
So there are three type of characters (yes, three, read on). Let 'v' be a vowel
and ''c be a consonant and '$' be a non-existent character (such as the end of
the text or beyond). Then the following rules apply:
Expand|Select|Wrap|Line Numbers
  1. vcv ---> v-cv
  2. vcc ---> vc-c
  3. vv$ ---> vv$
  4. vc$ ---> vc$
  5. v$$ ---> v$$
Basically when you've 'read' a consonant, simply emit it. When you've read a
vowel read two more characters and apply the rules outlined above.

kind regards,

Jos
May 22 '07 #11
just the same i have done, and it is working. i have a problem w/ output
May 22 '07 #12
JosAH
11,448 Expert 8TB
just the same i have done, and it is working. i have a problem w/ output
You must've done something else from what you've shown us. The code you've
shown reverses Strings, copies them to char arrays a couple of times and
mysteriously deals with '\0' characters. What exactly is working then and what
are the 'output problems'?

kind regards,

Jos
May 22 '07 #13
I understand your code somewhat but the way you use variables makes it confusing. Your question is on your output. If the code compiles until the output following the last for loop, I believe that is why you have the question marks on the array of char. One question I asked myself was that, how do you know what the exact size of str3 should be as you said when str3 is dependent on str2 and str2 is indirectly dependent on user input and there is no defined bound on the length of user inputted strings? Maybe that is where the problem is coming from. why not trim your code a little or rewrite these one with lots of comments, especially on the if-then statement where it searches for a vowel, I really got lost there. On why your output doesn’t work out, as I was saying, str3 is dependent on str2 from the for loop and you should make this evident in declaring str3, like this: char[] str3 = new char[Array.length(str2)]. Try it and see but I recommend you put lots of comment on that code if you want it to be readable and show declarations for your variables so we can know where the scopes are. I can’t see the scopes so I get lost on which variable is which.
It seems you want to control length of user input, then do so.
May 23 '07 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jack Smith | last post by:
Hello, I am working on the following problem. I need a divide and conquer algorithm to solve the following problem. Any help is appreciated. I have a set of coordinates (x,y) and each...
6
by: Nobody | last post by:
I have some code that I am trying to optimize for speed... trying to squeeze every last CPU cycle out... I remembered an old trick where dividing & multiplying can be sped up by using bitshifts...
6
by: pemo | last post by:
Does anyone know of an algorithm that can accurately determine the number of syllables in a given English word - esp. if that word isn't already 'known' by such an algorithm? FYI, there are two...
5
by: per.nordlow | last post by:
Hey there! I want to multiply/divide (shift) a float with variable containing a power-of-two value: 2, 4, 8, 16, .... Is there such a function in the C standard library or the glibc library...
12
by: dough | last post by:
I want to read in lines from a file and then seperate the words so i can do a process on each of the words. Say the text file "readme.txt" contains the following: In the face of criticism from...
4
by: shuisheng | last post by:
Dear all, Assume I have two big arrays A and B. And I want to element-wise divide A by B. When an element of B is zero, the results are also zero. Such as A = { 2, 4, 0, 6} B = { 1, 0, 0, 2}...
40
by: Spiros Bousbouras | last post by:
Do you have an example of an implementation where sizeof(short int) does not divide sizeof(int) or sizeof(int) does not divide sizeof(long int) or sizeof(long int) does not divide sizeof(long long...
1
by: Justin.Velazquez | last post by:
Hello everyone, I'm not really new to programming but my bitwise skills definately need work. I came across a problem I've been trying to figure out for fun. I'm trying to write a routine...
1
by: punjabplus | last post by:
hi i have long text of around 1000 words i want this text to divide in two text . and i want to pick first text from 5th (.) dot coming in the text. how can i do this i know the use of substring...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.