Hi All,
I have doubt in strncmp.
consider the following prog:
int main()
{
int i;
i = strncmp("Nstring","Astring",6);
printf("%d", i);
}
Here o/p is 13, now if i modify the prog like:
i = strncmp("Nstrisg","Astring",6); O/P is 5 why??
ok ok.. got it !! while typing the question i got the ANSWER.
it print the difference in the character.. Right?
3 1880
Hi All,
I have doubt in strncmp.
consider the following prog:
int main()
{
int i;
i = strncmp("Nstring","Astring",6);
printf("%d", i);
}
Here o/p is 13, now if i modify the prog like:
i = strncmp("Nstrisg","Astring",6); O/P is 5 why??
ok ok.. got it !! while typing the question i got the ANSWER.
it print the difference in the character.. Right?
That would clarify the first comparison: 'N'-'A' == 13 but what about the second
comparison then? It seems as if strncmp compares starting at the last character:
's'-'n' == 5 but that isn't a valid way to compare two strings lexicographically.
kind regards,
Jos
That would clarify the first comparison: 'N'-'A' == 13 but what about the second
comparison then? It seems as if strncmp compares starting at the last character:
's'-'n' == 5 but that isn't a valid way to compare two strings lexicographically.
kind regards,
Jos
OOps typing mistake.. Sorry man.. its:
i = strncmp("Nstrisg","Nstring",6); now for i = strncmp("Nstrisg","Astring",6);
Answer is 13 only..
OOps typing mistake.. Sorry man.. its:
i = strncmp("Nstrisg","Nstring",6); now for i = strncmp("Nstrisg","Astring",6);
Answer is 13 only..
Ah, ok, that explains it all: the diference of the two characters that are not equal
is the return value of the strncmp function: 'N'-'A' == 13 and 's'-'n' == 5.
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics
by: pembed2003 |
last post by:
Hi,
I have an application where I use the strncmp function extensively to
compare 2 string to see if they are the same or not. Does anyone know
a faster replacement for strncmp? I notice there is...
|
by: jacob navia |
last post by:
What is the result of that?
I am reimplementing the C library, and I would like to know.
Now I have it to return zero. Is that correct?
The standard says:
>>
The strncmp function compares...
|
by: Bert |
last post by:
I have a question about buffer overflows with strcmp or strncmp
(strnicmp). It's best described by providing an example
Example:
There is a string "sBuf" of length 5000. In a for loop from 0 to...
|
by: Preets |
last post by:
Hi,
Can anybody please tell me the difference between memcmp() and
strncmp() functions ?
|
by: Krumble Bunk |
last post by:
Hi all,
Having some trouble with a seemingly-simple task. Need to have a
basic CLI functionality as per:
prompt <- \n
prompt <- \n
promptquit <- should quit as per my snippet, but...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |