|
| |||||||||
| Tags: library in c, project, string, syntax |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| 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; ) |
|
#2
| ||||
| ||||
| 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
| |||
| |||
| 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
| |||
| |||
| 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. |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |