Results 1 to 6 of 6

Thread: Difference between two strings

  1. #1
    Join Date
    Oct 2009
    Posts
    9

    Difference between two strings

    I am currently working on a project to develop a library in C. I finally found a mistake that I did not expect and it's hard to explain.

    Code:
    # include <stdlib.h> 
    # include <stdio.h> 
    
    int main () 
    ( 
    char * string1 = "text", string2 [] = "text"; 
    printf ( "% d", sizeof (string1)); 
    printf ( "% d", sizeof (string2)); 
    
    return 0; 
    )
    I thought we would get the same result but not: string2 is greater than string1. Is there any difference between these 2 syntax ... Thank you for your help

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Difference between two strings

    string1 is a pointer: sizeof gives the size of the pointer. string2 is an array: sizeof gives the size of the table, because in string2 [] = "text" it is created automatically.

    In the first case, you're pointing a pointer to a string literal. In the second case, you initialize an array with the string.

  3. #3
    Join Date
    Jan 2009
    Posts
    199

    Re: Difference between two strings

    Check this example :
    Code:
     import org.apache.commons.lang.StringUtils;
    
    public class String1 {
    
      public static void main(String args[]) {
    
        System.err.println(StringUtils.getLevenshteinDistance("gov", "govern"));
      }
    }

  4. #4
    Join Date
    Dec 2008
    Posts
    177

    Re: Difference between two strings

    A string is a sequence of characters. Any sequence or set of characters defined within double quotation symbols is a constant string, Basically, you would cycle through each character in one string, and compare it to the corresponding character in the other. If the string or the character doesn't exist, then there is a difference.

  5. #5
    Join Date
    Dec 2013
    Posts
    1

    Re: Difference between two strings

    what is the means of ** 5.2 ** in this line and why we using this?
    printf("%5.2f",float);

  6. #6
    Join Date
    Dec 2007
    Posts
    2,291

    Re: Difference between two strings

    Quote Originally Posted by aasheeshk View Post
    what is the means of ** 5.2 ** in this line and why we using this?
    printf("%5.2f",float);
    When you are using %5.2, then you can easily come to know that all prices less than $1000 will line up on the decimal point and be good to read.

Similar Threads

  1. Files and strings in C
    By An1990 in forum Software Development
    Replies: 2
    Last Post: 10-05-2012, 10:11 PM
  2. How to use Strings in Python
    By Edmund-Windows in forum Software Development
    Replies: 5
    Last Post: 31-12-2010, 06:25 AM
  3. Strings in JavaFX
    By Messenger in forum Software Development
    Replies: 3
    Last Post: 16-07-2010, 04:57 PM
  4. Struct and Strings in C
    By Ash maker in forum Software Development
    Replies: 5
    Last Post: 05-04-2010, 12:31 PM
  5. Array of Strings in C++
    By Jaden in forum Software Development
    Replies: 3
    Last Post: 25-10-2008, 02:18 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,638,707.77917 seconds with 17 queries