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

Reply
 
Thread Tools Search this Thread
  #1  
Old 03-12-2009
Members
 
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
Member
 
Join Date: May 2008
Posts: 2,293
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
  #5  
Old 02-12-2013
Member
 
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);
Reply With Quote
  #6  
Old 03-12-2013
Member
 
Join Date: Dec 2007
Posts: 2,273
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Difference between two strings"
Thread Thread Starter Forum Replies Last Post
Files and strings in C An1990 Software Development 2 10-05-2012 10:11 PM
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 04:57 PM
Struct and Strings in C Ash maker Software Development 5 05-04-2010 12:31 PM
Array of Strings in C++ Jaden Software Development 3 25-10-2008 02:18 PM


All times are GMT +5.5. The time now is 09:23 PM.