Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , ,

Sponsored Links



Difference between two strings

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 03-12-2009
Member
 
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
Reply With Quote
  #2  
Old 03-12-2009
Zecho's Avatar
Member
 
Join Date: May 2008
Posts: 2,267
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.
Reply With Quote
  #3  
Old 03-12-2009
Member
 
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"));
  }
}
Reply With Quote
  #4  
Old 03-12-2009
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Difference between two strings"
Thread Thread Starter Forum Replies Last Post
How to use Strings in Python Edmund-Windows Software Development 5 31-12-2010 06:25 AM
Strings in JavaFX Messenger Software Development 3 16-07-2010 05:57 PM
Struct and Strings in C Ash maker Software Development 5 05-04-2010 01:31 PM
How to Compare Two Strings in C Pratim Software Development 3 28-12-2009 11:10 AM
Array of Strings in C++ Jaden Software Development 3 25-10-2008 03:18 PM


All times are GMT +5.5. The time now is 03:59 AM.