Zero-Length-String



Hello friends,
Is there any problem with "Zero-Length-String" in C/C++.
Pls mention if there is any type of problem in standard string library-functions like strcpy, strcat, memcpy, etc.

Thanx,
Amit


Related to : Zero-Length-String
length of string without using length function
C & C++ & C#

As c# doesnt have null character as in c I want to know how to find the length of string without using the length function???


How do I make a new String based on another string's unknown length?
C & C++ & C#

I am currently in a computer programming class and at a dead end for "creating a template" for this 2-person hang man game.

  • First, person#1 is prompted for a phrase (contains all lowercase)
  • Then, I must take whatever phrase they choose and turn it into a template with all ?'s.
  • Then, as person#2 guesses letters, I must "reveal" the phrase and have the ?'s turn into the phrase letters.

I can't get past turning it into the template though. An example is:

person#1's phrase: "hello world"

desired template outcome: "????? ?????"

This is what I have so far... I'm having trouble at public static String createTemplate(String sPhrase)

    import java.util.Scanner;

public class Program9 
{
public static void main (String[] args)
{
    Scanner scanner = new Scanner (System.in);
    Scanner stdIn = new Scanner (System.in);

    int cnt = 0; //counter is set to zero
    String sPhrase;
    boolean def;

    System.out.print("Enter a phrase consisting of only lowercase
letters and spaces: ");
    sPhrase = scanner.nextLine(); //reads into variable set to
Scanner.nextLine()


    System.out.println("


Common Phrase");
        System.out.println("--------------
");

        String template = createTemplate(sPhrase); //will run through
"createTemplate" and show whatever on there.

    do
    {

        char guess = getGuess(stdIn); //will run through "getGuess"
and show whatever SOP and return from that. WORKS.

        cnt = cnt + 1; //counts the guess

        System.out.println("


Common Phrase");
        System.out.println("--------------
");

        String updated = updateTemplate(template, sPhrase, guess);
//runs throuhgh and prints updated template




    } while (!exposedTemplate(sPhrase)); //will loop back if updated
template still has ?'s



    System.out.println("Good job! It took you " + cnt + " guesses!");
}
public static String createTemplate(String sPhrase)
{
    String template = null;
    String str;


    sPhrase.substring(0, sPhrase.length()+1); //not sure if +1 needed.
    sPhrase.equals(template);

    //THIS IS WHERE IM HAVING PROBLEMS



}
public static char getGuess(Scanner stdIn)
{
    //repeatedly prompts user for char response in range of 'a' to 'z'
    String guess;

    do
    {
        System.out.print("Enter a lowercase letter guess : ");
        guess = stdIn.next();
    } while (Character.isDigit(guess.charAt(0)));

    char firstLetter = guess.charAt(0);
    return firstLetter;
}

public static String changeCharAt(String str, int ind, char newChar)
{
    return str.substring(0, ind) + newChar + str.substring(ind+1);
    //freebie: returns copy of str with chars replaced

}
public static String updateTemplate(String template, String sPhrase,
char guess)
{
    //will have to include changeCharAt


}
public static boolean exposedTemplate(String template)
{
    // returns true exactly when there are no more ?'s

}
}

How to send length of a string in 2 bytes followed by the actual string which contains the text in MQ [on hold]
C & C++ & C#

Here is my scenario. We need to send a string message in MQ with the first 2 position containing the length of the message followed by the actual string containing the text. the first 2 positions are of size 2 bytes.how do i write the length of the message in 2 bytes. the receiver application is cobol based mainframe system. our application is in java platform so i need some advice or solution based on java.


How would I check if a part of a string equals another string of unknown length?
C & C++ & C#
        for(int j = 1;j<fileArray.size();j++) {
            if(str.contains(fileArray.get(end+j))) {

            }
        }

(assume end is some number such as 30). The goal of this part is when having a window length of 30 and a fileArray size > 30, check if theres anything after index 30 that matches whatever is inside the window.

So right now im using fileArray.get(end+j) to check if there's anything that matches within my string(str) except this doesn't really work. Is there a way I could fix this code segment?


Java Serial port string read [Determine string length]
C & C++ & C#

I am reading variable string from com port. Highest length of the string is 24. If I read string lower than that, for example it read 10 length string but still whenever I am measuring the length it always give 24. How to remove extra spaces if it is lower than highest length.

        serialPort.openPort();//Open serial port
        serialPort.setParams(9600, 8, 1, 0);//Set params.
        byte[] buffer = serialPort.readBytes(24);//Read 10 bytes from
serial port
        String str = new String(buffer);
        int t= str.length();
        System.out.println(t);

SQL : Splitting a column into multiple columns, by a common string separator where string has uneven length (TD14)
C & C++ & C#

I have an issue with splitting a variable I am recording, in which various values are separated with a @ sign. I want to separate the values into multiple columns and remove the string separator (@).

NB: The values are usually text, but may be of variable length.

I have both Googled, and searched Stackoverflow numerous times for solutions, but most are not applicable as I have a variable string length and also variable value length :(

Thanks in advance!

Example:

Original column
--------------------------------
Value1@Value2@Value3@Value4@Value5
Value1@Value2@Value3
Value1@Value2@Value3@Value4@Value5@Value6`

What I want:

Column1    Column2     Column3   Column4      Column5  
Column6
----------------------------------------------------------------------
Value1     Value2      Value3    Value4       Value5
Value1     Value2      Value3
Value1     Value2      Value3    Value4       Value5    Value6


Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © bighow.org All Rights Reserved .